Constructor
new LinkedList()
In computer science, a linked list is a linear collection of data elements,
in which linear order is not given by their physical placement in memory. Instead, each element
points to the next. It is a data structure consisting of a group of nodes which together represent
a sequence. Under the simplest form, each node is composed of data and a reference (in other words, a link)
to the next node in the sequence. Full wikipedia article at:
https://en.wikipedia.org/wiki/Linked_list
- Source:
Example
const LinkedList = require('dstructures').LinkedList;
const myLinkedList = new LinkedList();
Methods
GetElement(element)
Returns the element property of the given node.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
element |
any
|
Given element. |
Returns:
Returns element property of the given node.
insert(newElement, oldElement) → {Boolean}
Inserts a node in a linked list.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
newElement |
any
|
The element that will be inserted. |
oldElement |
any
|
The old element after whitch the new element will be added. At the first insertion this argument have to be ommited. |
Returns:
- Type:
-
Boolean
Returns false if the element is not present.
Example
LinkedList.insert(1); // [1]
LinkedList.insert(2, 1); // [1] -> [2]
LinkedList.insert(3, 2); // [1] -> [2] -> [3]
remove(element) → {Boolean}
Removes element from a linked list.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
element |
any
|
Given element. |
Returns:
- Type:
-
Boolean
Returns false if the element is not present.
Example
LinkedList; // [1] -> [2] -> [3]
LinkedList.remove(2); // [1] -> [3]
toArray() → {Array}
Returns array representation of the linked list.
- Source:
Returns:
- Type:
-
Array
Returns array representation of the linked list.
Example
LinkedList; // ['cat'] -> ['pig'] -> ['dog']
LinkedList.toArray(); // ['cat', 'pig', 'dog']