datastructure

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayStack

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

ArrayStack implements stack with slice

func NewArrayStack

func NewArrayStack[T any]() *ArrayStack[T]

NewArrayStack return a empty ArrayStack pointer

func (*ArrayStack[T]) Clear

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

Clear the stack data

func (*ArrayStack[T]) Data

func (s *ArrayStack[T]) Data() []T

Data return stack data

func (*ArrayStack[T]) IsEmpty

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

IsEmpty checks if stack is empty or not

func (*ArrayStack[T]) Peak

func (s *ArrayStack[T]) Peak() (*T, error)

Peak return the top element of stack

func (*ArrayStack[T]) Pop

func (s *ArrayStack[T]) Pop() (*T, error)

Pop delete the top element of stack then return it, if stack is empty, return nil and error

func (*ArrayStack[T]) Push

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

Push element into stack

func (*ArrayStack[T]) Size

func (s *ArrayStack[T]) Size() int

Size return length of stack data

type LinkedStack

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

LinkedStack implements stack with link list

func NewLinkedStack

func NewLinkedStack[T any]() *LinkedStack[T]

NewLinkedStack return a empty LinkedStack pointer

func (*LinkedStack[T]) Clear

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

Clear clear the stack data

func (*LinkedStack[T]) Data

func (s *LinkedStack[T]) Data() []T

Data return stack data

func (*LinkedStack[T]) IsEmpty

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

IsEmpty checks if stack is empty or not

func (*LinkedStack[T]) Peak

func (s *LinkedStack[T]) Peak() (*T, error)

Peak return the top element of stack then return it

func (*LinkedStack[T]) Pop

func (s *LinkedStack[T]) Pop() (*T, error)

Pop delete the top element of stack then return it, if stack is empty, return nil and error

func (*LinkedStack[T]) Print

func (s *LinkedStack[T]) Print()

Print all nodes info of stack link

func (*LinkedStack[T]) Push

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

Push element into stack

func (*LinkedStack[T]) Size

func (s *LinkedStack[T]) Size() int

Size return length of stack data

Jump to

Keyboard shortcuts

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