Documentation ¶
Overview ¶
Package linkedliststack implements a stack backed by a singly-linked list.
Structure is not thread safe.
Reference:https://en.wikipedia.org/wiki/Stack_%28abstract_data_type%29#Linked_list
Index ¶
- type Iterator
- type Stack
- func (stack *Stack[T]) Clear()
- func (stack *Stack[T]) Empty() bool
- func (stack *Stack[T]) FromJSON(data []byte) error
- func (stack *Stack[T]) Iterator() Iterator[T]
- func (stack *Stack[T]) MarshalJSON() ([]byte, error)
- func (stack *Stack[T]) Peek() (value T, ok bool)
- func (stack *Stack[T]) Pop() (value T, ok bool)
- func (stack *Stack[T]) Push(value T)
- func (stack *Stack[T]) Size() int
- func (stack *Stack[T]) String() string
- func (stack *Stack[T]) ToJSON() ([]byte, error)
- func (stack *Stack[T]) UnmarshalJSON(bytes []byte) error
- func (stack *Stack[T]) Values() []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Iterator ¶
type Iterator[T constraints.Ordered] struct { // contains filtered or unexported fields }
Iterator returns a stateful iterator whose values can be fetched by an index.
func (*Iterator[T]) Begin ¶
func (iterator *Iterator[T]) Begin()
Begin resets the iterator to its initial state (one-before-first) Call Next() to fetch the first element if any.
func (*Iterator[T]) First ¶
First moves the iterator to the first element and returns true if there was a first element in the container. If First() returns true, then first element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.
func (*Iterator[T]) Index ¶
Index returns the current element's index. Does not modify the state of the iterator.
func (*Iterator[T]) Next ¶
Next moves the iterator to the next element and returns true if there was a next element in the container. If Next() returns true, then next element's index and value can be retrieved by Index() and Value(). If Next() was called for the first time, then it will point the iterator to the first element if it exists. Modifies the state of the iterator.
func (*Iterator[T]) NextTo ¶
NextTo moves the iterator to the next element from current position that satisfies the condition given by the passed function, and returns true if there was a next element in the container. If NextTo() returns true, then next element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.
type Stack ¶
type Stack[T constraints.Ordered] struct { // contains filtered or unexported fields }
Stack holds elements in a singly-linked-list
func (*Stack[T]) Iterator ¶
Iterator returns a stateful iterator whose values can be fetched by an index.
func (*Stack[T]) MarshalJSON ¶
MarshalJSON @implements json.Marshaler
func (*Stack[T]) Peek ¶
Peek returns top element on the stack without removing it, or nil if stack is empty. Second return parameter is true, unless the stack was empty and there was nothing to peek.
func (*Stack[T]) Pop ¶
Pop removes top element on stack and returns it, or nil if stack is empty. Second return parameter is true, unless the stack was empty and there was nothing to pop.
func (*Stack[T]) Push ¶
func (stack *Stack[T]) Push(value T)
Push adds a value onto the top of the stack
func (*Stack[T]) UnmarshalJSON ¶
UnmarshalJSON @implements json.Unmarshaler