stack

package
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2021 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stack

type Stack[T any] struct {
	// contains filtered or unexported fields
}

Stack is a container adapter that gives the programmer the functionality of a stack - specifically, a LIFO (last-in, first-out) data structure.

func NewStack

func NewStack[T any]() *Stack[T]

NewStack TODO

func (*Stack[T]) Empty

func (s *Stack[T]) Empty() bool

Empty checks if the underlying container has no elements. Complexity - constant e.g. O(1). Returns true if the underlying container is empty, false otherwise.

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() T

Pop removes the top element from the Stack. Returns the object at the top of this Stack.

func (*Stack[T]) Push

func (s *Stack[T]) Push(item T)

Push pushes the given element value to the top of the Stack. Complexity - constant e.g. O(1).

func (*Stack[T]) Size

func (s *Stack[T]) Size() int

Size returns the number of elements in the underlying container. Complexity - constant e.g. O(1). Returns the number of elements in the container.

func (*Stack[T]) Top

func (s *Stack[T]) Top() T

Top returns reference to the top element in the Stack. This is the most recently pushed element. This element will be removed on a call to Pop. Complexity - constant e.g. O(1).

Jump to

Keyboard shortcuts

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