linkedliststack

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2016 License: BSD-2-Clause 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) 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(). 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) 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) 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