Go Structures!
Just GoLang Data Structures (with generics to handle all data types).
Nothing more, nothing less.
Headers have more in-depth documentation. Please wait while I finish more structures for more documentation.
Status:
Completed Structures:
- Trees
- Binary Search Trees
- Console Output
- Visualization (using Dotty by Graphviz)
- Linked Lists
- Stacks
- Linked List Based
- Array/Slice Based
- Queues
- Non-Priority Linked List Style
Planned Structures:
- Graphs
Vectors (?)
- Balance Trees (?)
- Heaps (Min and Max)
Documention
Lists
LinkedList
:
SinglyLinkedList
DoublyLinkedList
CircularList
Usable Methods:
//This applies to NewDoublyLinkedList and NewCircularList
container := list.NewSinglyLinkedList[int]()
container.PushFront(1)
container.PushBack(2)
container.Insert(2, 3) //Pos, Value
container.Insert(400, 4) //Special Case, just inserted at the back
element, err := container.Get(0)
list.RemoveFirst(func(v int) bool{
return v == 2
})
position, err := container.Search(func(v int) bool{
return v == 1;
})
noElements := container.Empty()
Queues
Queue
:
Usable Methods:
line := queue.NewLinkedQueue[string]()
line.Enqueue("John Doe")
frontOfLine := line.Peak()
nowServing := line.Dequeue()
arePeopleWaiting := line.Empty()
Stack
Stack
:
LinkedStack
ArrangedStack
Usable Methods:
//Applies to all stacks
example := stack.NewLinkedStack[float64]()
example.Push(3.1415)
example.Push(2.7878)
top := example.Peak()
using := example.Pop()
anythingLeft := example.Empty() //Bool
Tree
Tree
:
Usable Methods:
pine := tree.NewBinarySearchTree[string](
// Compares left and right to see which one is "bigger" (Used in Insertion/Deletion)
func(l, r string) bool {
return len(l) > len(r);
},
// This Checks for Equality (Used in Search/Deletion)
func(a, b string) bool {
return len(a) == len(b)
})
pine.Insert("A")
pine.Insert("BB")
pine.Insert("CCC")
pine.Insert("DDDD")
pine.Remove("A")
inList := pine.Search("A") //bool
//Useful Functions for Binary Search Trees (Using fmt.Printf("%v")):
func (b BinaryTree[T]) InorderPrint()
func (b BinaryTree[T]) PreorderPrint()
func (b BinaryTree[T]) PostorderPrint()
//If graphviz/dotty is installed:
func (b BinaryTree[T]) VisualizeDotty(fileName string) //Creates a .dot file, that dotty will use to make a .jpg file