stack

package
v0.0.0-...-ad0737c Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2020 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package stack implements a stack data structure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stack

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

Stack represents a stack data structure. The zero value for Stack is an empty stack ready to use.

func New

func New() *Stack

New returns an initialised stack.

func (*Stack) IsEmpty

func (s *Stack) IsEmpty() bool

IsEmpty returns true if the stack is empty, otherwise it returns false.

func (*Stack) Len

func (s *Stack) Len() int

Len returns the number of elements on the stack. The complexity is O(1).

func (*Stack) Peek

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

Peek returns the top element of the stack without removing it or nil if the stack is empty. The second parameter is false if the stack is empty, otherwise it is true.

func (*Stack) Pop

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

Pop removes and returns the top element of the stack or nil if the stack is empty. The second parameter is false if the stack is empty, otherwise it is true.

func (*Stack) Push

func (s *Stack) Push(v interface{})

Push inserts a new value v to the top of the stack.

Jump to

Keyboard shortcuts

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