stack

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package stack implements a stack built using a linked list.

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 that uses a linked list to store its elements.

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

func New1

func New1[T any](t T) *Stack[T]

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.

func (*Stack[T]) Swap

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

Swap swaps the top-most element for elem, returning the element previously at the top.

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

Jump to

Keyboard shortcuts

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