gqueue

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2023 License: MIT Imports: 2 Imported by: 0

README

gqueue

Generic Queue implementation in Go using linked list

Usage

s := gqueue.New(1, 2, 3, 4)
fmt.Println(s.Len())
fmt.Println(s.Pop())
fmt.Println(s.Pop())
fmt.Println(s.Pop())
fmt.Println(s.Pop())
s.Push(5)
fmt.Println(s.Peek())
// Output: 4
// 1
// 2
// 3
// 4
// 5

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GQueue

type GQueue[T any] struct {
	// contains filtered or unexported fields
}

GQueue is generic Queue implementation using linked list

Example
package main

import (
	"fmt"
	"github.com/sv-tools/gqueue"
)

func main() {
	s := gqueue.New(1, 2, 3, 4)
	fmt.Println(s.Len())
	fmt.Println(s.Pop())
	fmt.Println(s.Pop())
	fmt.Println(s.Pop())
	fmt.Println(s.Pop())
	s.Push(5)
	fmt.Println(s.Peek())
}
Output:

4
1
2
3
4
5

func New

func New[T any](items ...T) GQueue[T]

New creates an instance of GQueue and pushes all given items to the created queue

func (*GQueue[T]) Clear

func (s *GQueue[T]) Clear()

Clear clears the queue

func (*GQueue[T]) Len

func (s *GQueue[T]) Len() int

Len returns the length of the stack

func (*GQueue[T]) Peek

func (s *GQueue[T]) Peek() T

Peek returns the first item without removing it or a zero object of given type

func (*GQueue[T]) Pop

func (s *GQueue[T]) Pop() T

Pop returns the first item and removes it from the queue or returns a zero object of given type

func (*GQueue[T]) Push

func (s *GQueue[T]) Push(item T)

Push puts the given item into the queue

func (*GQueue[T]) String

func (s *GQueue[T]) String() string

String returns the list of all items in text format

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL