1.0.3 • Published 5 years ago

dl-doubly-linked-list-ts v1.0.3

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Doubly Linked List for TypeScript

A doubly linked-list implementation for TypeScript.

Installation

NPM

npm install dl-doubly-linked-list-ts

Build

tsc

Built JS files are in ./js.

Description

Node

A node is a vertex in the list, implemented in the DLNode class and has three fields:

FieldTypeGetterSetterDescription
dataT (generic)YesYesData object contained in the node.
nextDLNode | nullYesYesReference to next node, null if its last node.
preiousDLNode | nullYesYesReference to previous node. null if its first node.

Doubly Linked List

The doubly linked-list implementation is present in the DoublyLinkedList class. It has three fields:

FieldTypeGetterSetterDescription
lengthnumberYesNoNumber of nodes present in the list.
startDLNode | nullYesYesReference to start node, null if list is empty.
endDLNode | nullYesYesReference to last node. null if list is empty.

Documentation

Please refer to doc/index.html for the complete documentation and API reference. The documentation for this project was generated using Compodoc.

Demo

import { DoublyLinkedList, DLNode } from "./node_modules/dl-doubly-linked-list";

let list : DoublyLinkedList<any> = new DoublyLinkedList();

let nodes : DLNode<any>[] = [];
for(let i=0; i<10; i++) {
    nodes[i] = new DLNode(); 
    nodes[i].data = i * i;
    list.insertStart(nodes[i]);
}

// Inserting new node at the end
let newNode : DLNode<any> = new DLNode();
newNode.data = 300;
list.insert( newNode, 6 );

// Deleting a node
list.delete(4);

// Get array of the nodes
let array = list.toArray();

console.log(array);