stack

package
v0.0.0-...-a4a72b7 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2023 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 Array

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

func NewStack

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

NewStack creates and returns a new stack.

func (*Array[T]) IsEmpty

func (s *Array[T]) IsEmpty() bool

IsEmpty returns true if the stack is empty, false otherwise.

func (*Array[T]) Length

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

Size returns the number of elements in the stack.

func (*Array[T]) Peek

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

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

func (*Array[T]) Pop

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

Pop removes and returns the top element from the stack.

func (*Array[T]) Push

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

Push adds an element to the top of the stack.

type Node

type Node struct {
	Val  any
	Next *Node
}

Node structure

type SList

type SList struct {
	Stack *list.List
}

SList is our struct that point to stack with container/list.List library

func (*SList) IsEmpty

func (sl *SList) IsEmpty() bool

Empty check our stack has value or not

func (*SList) Length

func (sl *SList) Length() int

Length return length of our stack

func (*SList) Peek

func (sl *SList) Peek() (any, error)

Peak is return last value that insert into our stack

func (*SList) Pop

func (sl *SList) Pop() (any, error)

Pop is return last value that insert into our stack also it will remove it in our stack

func (*SList) Push

func (sl *SList) Push(val any)

Push add a value into our stack

type Stack

type Stack struct {
	// contains filtered or unexported fields
}

Stack has jost top of node and with length

func (*Stack) IsEmpty

func (ll *Stack) IsEmpty() bool

isEmpty to check our array is empty or not

func (*Stack) Length

func (ll *Stack) Length() int

len use to return length of our stack

func (*Stack) Peek

func (ll *Stack) Peek() any

peak return last input value

func (*Stack) Pop

func (ll *Stack) Pop() any

pop remove last item as first output

func (*Stack) Push

func (ll *Stack) Push(n any)

push add value to last index

func (*Stack) Show

func (ll *Stack) Show() (in []any)

show all value as an interface array

Jump to

Keyboard shortcuts

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