A node based basic data structures library with type safety. Following data structures are currently supported.
For example to create a LinkedList, use the following snippet:
var structures = require("all-structures");
var list = new structures.LinkedList({type: String, maxSize: 4});
An array list is a simple list data structure with an array implementation underneath. While creating an array list, following options are supported:
{
maxSize: 10, //the maximum size of the list, defaults to machine specific maximum
type: String //type of the objects to be added to the list. Required option!
}
-
add()
list.add("Hello")
-
remove()
list.remove(0);
-
size()
list.size();
-
toString()
list.toString();
-
get()
list.get(0);
A Linked list is a Singly LinkedList implementation While creating a linked list, following options are supported:
{
maxSize: 10, //the maximum size of the list, defaults to machine specific maximum
type: String //type of the objects to be added to the list. Required option!
}
-
add()
list.add("Hello")
-
remove()
list.remove(0);
-
size()
list.size();
-
toString()
list.toString();
-
get()
list.get(0);
-
next() - gets the next node. Returns undefined if reached to end.
list.next();
A doubly linked list can be traversed in both directions. While creating a doubly linked list, following options are supported:
{
maxSize: 10, //the maximum size of the list, defaults to machine specific maximum
type: String //type of the objects to be added to the list. Required option!
}
-
add()
list.add("Hello")
-
remove()
list.remove(0);
-
size()
list.size();
-
toString()
list.toString();
-
get()
list.get(0);
-
next() - gets the next node. Returns undefined if reached to end.
list.next();
-
prev() - gets the previous node. Returns undefined if reached to start.
list.prev();
Install dependencies
$ npm install
Run the mocha test cases
$ mocha