DataStructure-KT is an open-source project that provides a set of common data structures implemented in Kotlin.
DataStructure-KT provides the following data structures:
- Stack
- Queue
- Singly Linked List
- Doubly Linked List
- Binary Search Tree
DataStructure-KT is available on Maven Central. To use it in your project, add the following dependency to your build file:
implementation 'com.github.ch8n.DataStructureKT:linked-list-kt:Version'
val stack = Stack()
stack.push(1)
stack.push(2)
stack.push(3)
println(stack.pop()) // Output: 3
val queue = Queue()
queue.enqueue(1)
queue.enqueue(2)
queue.enqueue(3)
println(queue.dequeue()) // Output: 1
val linkedList = SinglyLinkedList()
linkedList.addFirst(1)
linkedList.addLast(2)
linkedList.addLast(3)
println(linkedList.first()) // Output: 1
val linkedList = DoublyLinkedList()
linkedList.addFirst(1)
linkedList.addLast(2)
linkedList.addLast(3)
println(linkedList.last()) // Output: 3
val bst = BinarySearchTree()
bst.insert(5)
bst.insert(3)
bst.insert(7)
bst.insert(1)
bst.insert(4)
bst.insert(6)
bst.insert(8)
println(bst.contains(3)) // Output: true
For more usage examples, check out the tests directory.
Contributions are welcome! If you find a bug or have a feature request, please open an issue. If you want to contribute code, please open a pull request.