node-structures
Basic Data Structures for use in JavaScript (server-side, client side)
Description
The Library provides the following Data Structure Implementations
Installation
Server-side: npm install node-structures
Client-side: bower install node-structures
Usage
Stack
const Stack = Stack;let stack = ;/*** Tests if this stack is empty.* @returns*/stack;/*** Pushes an item onto the top of this stack.* @param item - the item to be pushed onto this stack.* @return*/stack;/*** Looks at the object at the top of this stack without removing it from the stack.* @throws* @returns*/stack;/*** Removes the object at the top of this stack and returns that object as the value of this function.* @throws* @return*/stack;/*** Returns the size of the stack.* @returns*/stacksize;
Queue
const Queue = Queue;let queue = ;/*** Returns the size of the queue.* @returns*/queuesize;/*** Tests if this queue is empty.* @returns*/queue;/*** Inserts the specified element into this queue.* @param element - the element to add* @return*/queue;/*** Retrieves and removes the head of this queue. This method differs from poll only in that it throws an exception* if this queue is empty.* @throws* @return*/queue;/*** Retrieves and removes the head of this queue, or returns null if this queue is empty.* @returns*/queue;/*** Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.* @returns*/queue;
Priority Queue
const PriorityQueue = PriorityQueue;/*** Creates an empty PriorityQueue with default comparator.** Default Comparator: Compares `a` and `b`, when `a > b` it returns a positive number, when `a` = `b` it returns 0,* and when `a < b` it returns a negative number.*/let priorityQueue = ;/*** Creates an empty PriorityQueue with custom comparator.** (`a > b` - return a positive number, when `a` = `b` return 0, and when `a < b`) return a negative number.*/const comparator = {return a - b; // define your own one.};let priorityQueue = comparator;/*** Returns the number of elements in this collection** @returns*/priorityQueuesize;/*** Tests if this priority queue is empty.** @returns*/priorityQueue;/*** Inserts the specified element into this priority queue.** @param element - the element to add* @returns*/priorityQueue;/*** Retrieves and removes the head of this priority queue, or returns null if this priority queue is empty.** @returns*/priorityQueue;/*** Retrieves, but does not remove, the head of this priority queue, or returns null if this priority queue is empty.** @returns*/priorityQueue;
Linked List
const LinkedList = LinkedList;let linkedList = ;/*** Tests if this LinkedList is empty.* @returns*/linkedList;/*** Inserts the specified element at the beginning of this list.* @param data - the element to add*/linkedList;/*** Appends the specified element to the end of this list.* @param data - the element to add*/linkedList;/*** Inserts the specified element at the specified position in this list.* Shifts the element currently at that position (if any) and any subsequent elements to the right* (adds one to their indices).* @throws IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())* @param index - index at which the specified element is to be inserted* @param element - element to be inserted*/linkedList;/*** Removes the element at the specified position in this list. Shifts any subsequent elements to the left* (subtracts one from their indices).* Returns the element that was removed from the list.* @throws IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())* @param index - the index of the element to be removed* @returns*/linkedList;/*** Returns the element at the specified position in this list.* @throws IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())* @param index - index of the element to return* @returns*/linkedList;/*** Returns the number of elements in this list.* @returns*/linkedListsize;/*** Removes all of the elements from this list. The list will be empty after this call returns.*/linkedListclear;
License
MIT