linkedstack

package
v0.0.0-...-2a10efc Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iterator

type Iterator[T comparable] struct {
	// contains filtered or unexported fields
}

Iterator represents an iterator of array stack.

func (*Iterator[T]) Begin

func (it *Iterator[T]) Begin()

Begin resets the iterator to its initial state.

func (*Iterator[T]) End

func (it *Iterator[T]) End()

End resets the iterator to its final state.

func (*Iterator[T]) First

func (it *Iterator[T]) First() bool

First moves the iterator to its first element.

func (*Iterator[T]) Index

func (it *Iterator[T]) Index() int

Index returns the current index of the iterator. Does not modify the state of the iterator.

func (*Iterator[T]) Last

func (it *Iterator[T]) Last() bool

Last moves the iterator to its last element.

func (*Iterator[T]) Next

func (it *Iterator[T]) Next() bool

Next returns true if there are more elements in the iterator.

func (*Iterator[T]) Prev

func (it *Iterator[T]) Prev() bool

Prev returns true if there are more elements in the iterator.

func (*Iterator[T]) Value

func (it *Iterator[T]) Value() T

Value returns the current element of the iterator. Does not modify the state of the iterator.

type Stack

type Stack[T comparable] struct {
	// contains filtered or unexported fields
}

Stack is a last-in-first-out (LIFO) stack of elements. hold a linkedlist.

func New

func New[T comparable]() *Stack[T]

New creates a new stack.

func (*Stack[T]) Clear

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

Clear clear this stack.

func (*Stack[T]) Empty

func (s *Stack[T]) Empty() bool

Empty return true if the stakc is empty

func (*Stack[T]) FromJSON

func (s *Stack[T]) FromJSON(data []byte) error

FromJSON populates list's elements from the input JSON representation.

func (*Stack[T]) Iterator

func (s *Stack[T]) Iterator() *Iterator[T]

Iterator returns an iterator of the array stack.

func (*Stack[T]) Peek

func (s *Stack[T]) Peek() (t T, _ bool)

Peek return the peek value of the stack if stack is empty return (zero-value, false)

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() (t T, _ bool)

Pop removes the top element from the stack and returns it. It returns (zero-value, false) if the stack is empty.

func (*Stack[T]) Push

func (s *Stack[T]) Push(elem T)

Push adds a new element to the top of the stack.

func (*Stack[T]) Size

func (s *Stack[T]) Size() int

Size return size of this stack.

func (*Stack[T]) String

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

String returns a string represent this stack.

func (*Stack[T]) ToJSON

func (s *Stack[T]) ToJSON() ([]byte, error)

ToJSON outputs the JSON representation of list's elements.

func (*Stack[T]) Values

func (s *Stack[T]) Values() []T

Values return values the stack hole.

Jump to

Keyboard shortcuts

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