stack

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2023 License: MIT Imports: 0 Imported by: 1

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 used to implement the last-in first-out.

func New

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

New is used to create a new instance of the stack.

func (*Stack[T]) Length

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

Length is used to return the number of elements in the stack.

func (*Stack[T]) Peek

func (s *Stack[T]) Peek() (a T, b bool)

Peek is used to access the top-most element from the stack.

If there are no elements in the stack, then the default value of the type is returned and a boolean value false stating that no elements were popped.

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() (a T, b bool)

Pop is used to remove the top-most element from the stack. It returns the value of the removed element.

If there are no elements in the stack, then the default value of the type is returned and a boolean value false stating that no elements were popped.

func (*Stack[T]) Push

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

Push is used to push an element to the stack.

Jump to

Keyboard shortcuts

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