Skip to content

circles-00/go_data_structures

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Data structures in GoLang

This is just a repository for data structures that I'm usually using with GoLang These data structures are my implementations and I'm most of the time using them for leetcode.

Table of Content

Testing

For each data structure there is a test file where all the tests for that particular data structures are written.

For running all the tests please run the test.sh scripts from the root of the project.

./test.sh

Usage

Queues

Array Queue

Initialization

So, I'm aiming for all my data structures to be generic, since I want to use them in different contexts. While initializing the queue, you can use the utility function NewArrayQueue which will return a new instance of the ArrayQueue implementation

queue := NewArrayQueue[int]()

Enqueuing an Element

queue.Enqueue(1)

Dequeuing an Element

Dequeues the front Element and returns it

dequeuedElement := queue.Dequeue()

Peeking an Element

Returns the front Element of the ArrayQueue without removing it.

peekedElement := queue.Peek()

Clearing the Queue

Removes all the elements from the Queue.

queue.Clear()

Checking whether the Queue is empty or not

isEmpty := queue.IsEmpty()

Checking the size of the Queue

size := queue.Size

Accessing all the Elements of the Queue

This will give you the slice instance that was created once initializing the ArrayQueue

elements := queue.Elements

Stacks

ArrayStack

Initialization

While initializing the stack, you can use the utility function NewArrayStack which will return a new instance of the ArrayStack implementation

stack := NewArrayStack[int]()

Pushing an element to the stack

stack.Push(1)

Poping an element from the stack

Removes the last Element from the Stack and returns it

poppedElement := stack.Pop()

Peeking an element from the stack

Returns the last Element from the Stack without removing it

lastElement := stack.Peek()

Clearing the stack

Removes all the Elements from the stack

stack.Clear()

Checking whether the stack is empty

isEmpty := stack.IsEmpty()

Contributing

I'm not looking for contributors, as this is just my hobby repository where I'm keeping all of the data structures that I need, but of course if you spot bugs, or any issues feel free to open a PR or issue, I'll be happy to review it.

About

Data Structures that I use with GoLang

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published