Skip to content

Typescript implementation for data structure using functions/classes

Notifications You must be signed in to change notification settings

kirhammer/data-structures

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Data Structures

This project implements a few data structures as Typescript classes. Some of the structures are: queue, singly linked list...

Compile

src folder can be compiled to Javascript, through @babel/preset-typescript. Output files are saved in lib. To compile, run the following command:

node run compile

Test

Unit tests are run through the following command:

node test

Classes

Singly Linked List

This structure allows to move between nodes in the foward direction only. An instance of this class contains 3 parameters:

  • size: Amount of linked nodes in list
  • head: A reference to the first node of the list
  • tail: A reference to the last node of the list

Also, there are several operations that can be applied to the list, such as:

const list = new SinglyLinkedList()

//Pushes item at the begining of the list
list.pushToHead("First item")

//Pushes item at the end of the list
list.pushToTail("Last item")

//Pushes item at the specified index
list.insert("Second item", 1)

//Deletes item at the begnining of the list
list.popHead()

//Deletes item at the end of the list
list.popTail()

//Deletes item at the specified index
list.delete(1)

//Returns item at the specified index
const node: SinglyNode = list.search(1)

//Returns a string representation of the list
const string: string = list.toString()

About

Typescript implementation for data structure using functions/classes

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published