Skip to content

fuad7161/dsgo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Data Structures – dsgo

A generic data structures library in Go, designed to be simple, reusable, and efficient.


📦 Installation

To use this repository in your Go project, run:

go get github.com/fuad7161/dsgo

Jump to Specific Data Structures

Linear Data Structures Tree-Based Structures Hash-Based Structures Heap Structures Graph Structures Others / Advanced
Stack Binary Tree Hash Table Min Heap Graph LRU Cache
Queue Binary Search Tree Bloom Filter Max Heap Union-Find (Disjoint Set) Skip List
Circular Queue AVL Tree D-ary Heap Suffix Array
Priority Queue Red-Black Tree Fibonacci Heap Suffix Tree
Deque Segment Tree Fenwick Tree (Binary Indexed Tree)
Singly Linked List Trie (Prefix Tree) KD Tree
Doubly Linked List B-Tree
Circular Linked List B+ Tree

Stack

🧭 Stack Methods Overview | 🔝 Back to Top

func main() {
	// Create a stack of integers
	stack := dsgo.NewStack[int]()

	// Push elements
	stack.Push(10)
	stack.Push(20)
	stack.Push(30)

	// Peek top element
	top, _ := stack.Peek()
	fmt.Println("Top:", top) // Output: Top: 30

	// Pop elements
	val, _ := stack.Pop()
	fmt.Println("Popped:", val) // Output: Popped: 30

	// Stack length
	fmt.Println("Length:", stack.Len()) // Output: Length: 2

	// Check if empty
	fmt.Println("Is empty?", stack.Empty()) // Output: Is empty? false

	// Convert to slice
	slice := stack.ToSlice()
	fmt.Println("Slice:", slice) // Output: Slice: [10 20]

	// Clear the stack
	stack.Clear()
	fmt.Println("Cleared. Is empty?", stack.Empty()) // Output: Cleared. Is empty? true
}

Queue

🧭 Queue Methods Overview | 🔝 Back to Top

func main() {
	// Create a queue of integers
	queue := dsgo.NewQueue[int]()

	// Push elements
	queue.Push(10)
	queue.Push(20)
	queue.Push(30)

	// Peak front element
	front, _ := queue.Peak()
	fmt.Println("Front:", front) // Output: Front: 10

	// Pop elements
	val, _ := queue.Pop()
	fmt.Println("Popped:", val) // Output: Popped: 10

	// Queue length
	fmt.Println("Length:", queue.Len()) // Output: Length: 2

	// Check if empty
	fmt.Println("Is empty?", queue.Empty()) // Output: Is empty? false

	// Convert to slice
	slice := queue.ToSlice()
	fmt.Println("Slice:", slice) // Output: Slice: [20 30]

	// Clear the queue
	queue.Clear()
	fmt.Println("Cleared. Is empty?", queue.Empty()) // Output: Cleared. Is empty? true
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages