stack

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2022 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package stack provides a stack datatype built using a resized slice.

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 stack using a resized slice to store its elements.

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

func New

func New[T any](initialCap int) Stack[T]

New creates a new Stack with the given initial capacity.

func (*Stack[T]) Clone

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

Clone clones the stack, returning a Stack with a copy of the underlying slice.

func (*Stack[T]) Len

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

Len returns the length of the stack.

func (*Stack[T]) Peek

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

Peek returns the element at the top of the stack without removing it.

If the stack is of length 0, Peek will panic.

func (*Stack[T]) Pop

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

Pop takes the top most element from the stack and removes it.

If the stack is of length 0, Pop will panic.

func (*Stack[T]) Push

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

Push puts elem on top of the stack.

Jump to

Keyboard shortcuts

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