linkedliststacks

package
v0.0.0-...-5ce2504 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2023 License: MIT Imports: 2 Imported by: 0

README

Description

Implement a Stack using a linked list. A stack is an abstract data type that serves as a collection of elements, with two principal operations: push, which adds an element to the collection, and pop, which removes the most recently added element that was not yet removed

Example:

Input: Push "value1", Push "value2", Push "value3", Pop 
Output: ["value2", "value1"]

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 stack structure

func New

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

New factory to generate new stacks

func (*Stack[T]) Clear

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

Clear clears stack

func (*Stack[T]) GetValues

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

GetValues returns values

func (*Stack[T]) IsEmpty

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

IsEmpty checks if the stack is empty

func (*Stack[T]) Peek

func (s *Stack[T]) Peek() (res T, err error)

Peek returns top of the stack

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() (res T, err error)

Pop remove from the stack

func (*Stack[T]) Push

func (s *Stack[T]) Push(values ...T)

Push add to the stack

func (*Stack[T]) Size

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

Size returns size of the stack

Jump to

Keyboard shortcuts

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