linkedlists

package
v0.0.0-...-03d60e9 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RemoveFirstStrategy = iota
	RemoveAllStrategy
)

Variables

This section is empty.

Functions

func InsertAfter

func InsertAfter[T comparable](nodeBefore *Node[T], nodeAfter *Node[T])

func RemoveAfter

func RemoveAfter[T comparable](node *Node[T])

Types

type Animal

type Animal interface {
	Speak()
}

type AnimalShelter

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

type Cat

type Cat struct{}

func (Cat) Speak

func (c Cat) Speak()

type ComparableStack

type ComparableStack[T cmp.Ordered] struct {
	Stack[T]
}

func (*ComparableStack[T]) Sort

func (left *ComparableStack[T]) Sort()

type Dog

type Dog struct{}

func (Dog) Speak

func (d Dog) Speak()

type IntThreeStack

type IntThreeStack ThreeStack[uint32]

func (*IntThreeStack) IsEmpty

func (ts *IntThreeStack) IsEmpty(stack byte) bool

func (*IntThreeStack) Peek

func (ts *IntThreeStack) Peek(stack byte) (uint32, error)

func (*IntThreeStack) Pop

func (ts *IntThreeStack) Pop(stack byte) (uint32, error)

func (*IntThreeStack) Push

func (ts *IntThreeStack) Push(stack byte, value uint32) error

type MinStack

type MinStack[T cmp.Ordered] struct {
	// contains filtered or unexported fields
}

func (*MinStack[T]) IsEmpty

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

func (*MinStack[T]) Min

func (s *MinStack[T]) Min() (T, bool)

func (*MinStack[T]) Peek

func (s *MinStack[T]) Peek() (T, bool)

func (*MinStack[T]) Pop

func (s *MinStack[T]) Pop() (T, bool)

func (*MinStack[T]) Push

func (s *MinStack[T]) Push(i T)

type MinStack2

type MinStack2[T cmp.Ordered] struct {
	// contains filtered or unexported fields
}

func (*MinStack2[T]) IsEmpty

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

func (*MinStack2[T]) Min

func (s *MinStack2[T]) Min() (T, bool)

func (*MinStack2[T]) Peek

func (s *MinStack2[T]) Peek() (T, bool)

func (*MinStack2[T]) Pop

func (s *MinStack2[T]) Pop() (T, bool)

func (*MinStack2[T]) Push

func (s *MinStack2[T]) Push(i T)

type MyQueue

type MyQueue[T comparable] struct {
	// contains filtered or unexported fields
}

func (*MyQueue[T]) Dequeue

func (q *MyQueue[T]) Dequeue() (T, bool)

func (*MyQueue[T]) Enqueue

func (q *MyQueue[T]) Enqueue(v T)

func (*MyQueue[T]) Peek

func (q *MyQueue[T]) Peek() (T, bool)

type Node

type Node[T comparable] struct {
	// contains filtered or unexported fields
}

func AppendNode

func AppendNode[T comparable](list *Node[T], node *Node[T]) *Node[T]

func CreateNode

func CreateNode[T comparable](data T) *Node[T]

func RemoveAllNodesWithValue

func RemoveAllNodesWithValue[T comparable](list *Node[T], data T) *Node[T]

func RemoveFirstNodeWithValue

func RemoveFirstNodeWithValue[T comparable](list *Node[T], data T) *Node[T]

func RemoveNodesWithValueUsingStrategy

func RemoveNodesWithValueUsingStrategy[T comparable](list *Node[T], data T, strategy RemoveStrategy) *Node[T]

func ReverseList

func ReverseList[T comparable](list *Node[T]) *Node[T]

func SearchNodeIteratively

func SearchNodeIteratively[T comparable](list *Node[T], data T) *Node[T]

func SearchNodeRecursively

func SearchNodeRecursively[T comparable](list *Node[T], data T) *Node[T]

func (*Node[T]) ToString

func (list *Node[T]) ToString() string

type Queue

type Queue[T comparable] struct {
	// contains filtered or unexported fields
}

func (*Queue[T]) Add

func (q *Queue[T]) Add(i T)

func (*Queue[T]) IsEmpty

func (q *Queue[T]) IsEmpty() bool

func (*Queue[T]) Peek

func (q *Queue[T]) Peek() (T, bool)

func (*Queue[T]) Print

func (q *Queue[T]) Print()

func (*Queue[T]) Remove

func (q *Queue[T]) Remove() (T, bool)

type RemoveStrategy

type RemoveStrategy int8

type SortedStack

type SortedStack[T cmp.Ordered] struct {
	Stack[T]
}

Write a program to sort a stack such that the smallest items are on the top. You can use an additional temporary stack, but you may not copy the elements into any other data structure (such as an array). The stack supports the following operations: push, pop, peek, and isEmpty.

I could simply push the element if the top of the stack is ermpty or equal or greater than the pushed value. If the top of the stack is smaller, I pop from that stack and I push to the temp stack until the top of the stack is empty or greater than or equal to the pushed value, and then push the given value, and then pop from the temp stack to the stack until the temp stack is empty.

Otherwise, pop, peek, and isEmpty are all the same as a normal stack.

func (*SortedStack[T]) Push

func (s *SortedStack[T]) Push(v T)

type Stack

type Stack[T comparable] struct {
	// contains filtered or unexported fields
}

func (*Stack[T]) IsEmpty

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

func (*Stack[T]) Peek

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

func (*Stack[T]) Pop

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

func (*Stack[T]) Print

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

func (*Stack[T]) Push

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

type StackOfStacks

type StackOfStacks[T comparable] struct {
	// contains filtered or unexported fields
}

func (*StackOfStacks[T]) IsEmpty

func (ss *StackOfStacks[T]) IsEmpty() bool

func (*StackOfStacks[T]) Peek

func (ss *StackOfStacks[T]) Peek() (T, bool)

func (*StackOfStacks[T]) Pop

func (ss *StackOfStacks[T]) Pop() (T, bool)

func (*StackOfStacks[T]) PopAt

func (ss *StackOfStacks[T]) PopAt(stack int) (T, bool)

func (*StackOfStacks[T]) Push

func (ss *StackOfStacks[T]) Push(v T)

type ThreeStack

type ThreeStack[T comparable] struct {
	// contains filtered or unexported fields
}

func (*ThreeStack[T]) IsEmpty

func (ts *ThreeStack[T]) IsEmpty(stack int) bool

func (*ThreeStack[T]) Peek

func (ts *ThreeStack[T]) Peek(stack int) (T, error)

func (*ThreeStack[T]) Pop

func (ts *ThreeStack[T]) Pop(stack int) (T, error)

func (*ThreeStack[T]) Push

func (ts *ThreeStack[T]) Push(stack int, value T) error

type TimestampedNode

type TimestampedNode[T comparable] struct {
	// contains filtered or unexported fields
}

func CreateTimestampedNode

func CreateTimestampedNode[T comparable](value T, timestamp int64) *TimestampedNode[T]

Jump to

Keyboard shortcuts

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