arraystack

package
v0.0.0-...-8cfa9df Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: MIT Imports: 2 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 holds elements in an array-list

func New

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

New instantiates a new empty stack

func (*Stack[T]) Clear

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

Clear removes all elements from the stack.

func (*Stack[T]) Empty

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

Empty returns true if stack does not contain any elements.

func (*Stack[T]) Len

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

Len returns number of elements within the stack.

func (*Stack[T]) Peek

func (s *Stack[T]) Peek() (value T, 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[T]) Pop

func (s *Stack[T]) Pop() (value T, 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[T]) Push

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

Push adds a value onto the top of the stack

func (*Stack[T]) Values

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

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