linkedliststack

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2018 License: BSD-2-Clause, ISC Imports: 5 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iterator

type Iterator struct {
	// contains filtered or unexported fields
}

Iterator returns a stateful iterator whose values can be fetched by an index.

func (*Iterator) Begin added in v1.2.0

func (iterator *Iterator) Begin()

Begin resets the iterator to its initial state (one-before-first) Call Next() to fetch the first element if any.

func (*Iterator) First added in v1.2.0

func (iterator *Iterator) First() bool

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) Index

func (iterator *Iterator) Index() int

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

func (*Iterator) Next

func (iterator *Iterator) Next() bool

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) Value

func (iterator *Iterator) Value() interface{}

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

type Stack

type Stack struct {
	// contains filtered or unexported fields
}

Stack holds elements in a singly-linked-list

func New

func New() *Stack

New nnstantiates a new empty stack

func (*Stack) Clear

func (stack *Stack) Clear()

Clear removes all elements from the stack.

func (*Stack) Empty

func (stack *Stack) Empty() bool

Empty returns true if stack does not contain any elements.

func (*Stack) FromJSON added in v1.9.0

func (stack *Stack) FromJSON(data []byte) error

FromJSON populates the stack from the input JSON representation.

func (*Stack) Iterator

func (stack *Stack) Iterator() Iterator

Iterator returns a stateful iterator whose values can be fetched by an index.

func (*Stack) Peek

func (stack *Stack) Peek() (value interface{}, ok bool)

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) Pop

func (stack *Stack) Pop() (value interface{}, ok bool)

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) Push

func (stack *Stack) Push(value interface{})

Push adds a value onto the top of the stack

func (*Stack) Size

func (stack *Stack) Size() int

Size returns number of elements within the stack.

func (*Stack) String

func (stack *Stack) String() string

String returns a string representation of container

func (*Stack) ToJSON added in v1.9.0

func (stack *Stack) ToJSON() ([]byte, error)

ToJSON outputs the JSON representation of the stack.

func (*Stack) Values

func (stack *Stack) Values() []interface{}

Values returns all elements in the stack (LIFO order).

Jump to

Keyboard shortcuts

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