ch8n / DataStructureKT

Kotlin Implementation of Datastructure

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DataStructure-KT

DataStructure-KT is an open-source project that provides a set of common data structures implemented in Kotlin.

Table of Contents

Features

DataStructure-KT provides the following data structures:

  • Stack
  • Queue
  • Singly Linked List
  • Doubly Linked List
  • Binary Search Tree

Installation

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' 

Usage

Stack

val stack = Stack()
stack.push(1)
stack.push(2)
stack.push(3)
println(stack.pop()) // Output: 3

Queue

val queue = Queue()
queue.enqueue(1)
queue.enqueue(2)
queue.enqueue(3)
println(queue.dequeue()) // Output: 1

Singly Linked List

val linkedList = SinglyLinkedList()
linkedList.addFirst(1)
linkedList.addLast(2)
linkedList.addLast(3)
println(linkedList.first()) // Output: 1

Doubly Linked List

val linkedList = DoublyLinkedList()
linkedList.addFirst(1)
linkedList.addLast(2)
linkedList.addLast(3)
println(linkedList.last()) // Output: 3

Binary Search Tree

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.

Contributing

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.

License

DataStructure-KT is released under the

About

Kotlin Implementation of Datastructure


Languages

Language:Kotlin 100.0%