/stack

Go implementation of stack using slice

Primary LanguageGoMIT LicenseMIT

stack

-- import "github.com/darylnwk/stack"

Usage

type Stack

type Stack struct {
}

Stack defines a thread safe stack

func New

func New() *Stack

New initialises a new Stack

func (*Stack) Peek

func (s *Stack) Peek() interface{}

Peek returns the element at the top of the stack

func (*Stack) Pop

func (s *Stack) Pop() interface{}

Pop returns the top element and nil if the stack is empty

func (*Stack) Push

func (s *Stack) Push(elements ...interface{})

Push adds elements to the stack

func (*Stack) Size

func (s *Stack) Size() int

Size returns the total number of elements in the stack