- create and test merge
- create and test sort
- test contain
- test pos
- test getElemAtPos
- test reduce
- test slice
- test spice
- optimize sort function
- update readme api documentation
npm install lucabro-linked-list --save
import {LinkedList} from "lucabro-linked-list/package/LinkedList";
- Properties
- Methods
- init(c: {new (data: any): T;}, init_data?: Array<any>): void
- addElem(data: any, ll?: LinkedList<T>): LinkedList<T>
- addElemRight(data: any, ll?: LinkedList<T>): LinkedList<T>
- addElemLeft(data: any, ll?: LinkedList<T>): LinkedList<T>
- removeElem(elem?: T): LinkedList<T>
- removeElemByPos(pos: number): LinkedList<T>
- removeElemByData(data: any): LinkedList<T>
- insertElem(data: any, pos?: number): LinkedList<T>
- length(): number
- toStart(ll?: LinkedList<T>): LinkedList<T>
- toNext(ll?: LinkedList<T>): LinkedList<T>
- toPrev(ll?: LinkedList<T>): LinkedList<T>
- toEnd(ll?: LinkedList<T>): LinkedList<T>
- get(): T
- destroy(): void
- isStart(elem?: T): boolean
- isEnd(elem?: T): boolean
- clone(return_cloned?: boolean): LinkedList<T>
- concat(list_to_append: LinkedList<T>): LinkedList<T>
- rMerge(list_to_merge: LinkedList<T>, func?: Function): LinkedList<T>
- merge(list_to_merge: LinkedList<T>, func?: Function): LinkedList<T>
- toArray(): Array<any>
- rSort(sort_func?: Function, list?: LinkedList<T>): LinkedList<T>
- sort(sort_func?: Function, list?: LinkedList<T>): LinkedList<T>
- isEqual(list: LinkedList<T>, equality_func?: (a: T, b: T) => boolean): boolean
Pointer to the head of the list
Pointer to the end of the list
Reference to the cloned list
Pointer to the previous element of the list with respect of the current element
Value of the current element
Pointer to the next element of the list with respect of the current element
var ll:LinkedList<ElementType> = new LinkedList<ElementType>();
Constructor
var ll:LinkedList<ElementType> = new LinkedList<ElementType>();
ll.init(ElementType);
or
var ll:LinkedList<ElementType> = new LinkedList<ElementType>();
ll.init(ElementType, ['data1', 'data2', 'data3']);
Init list, with or without initial data
var ll:LinkedList<ElementType> = new LinkedList<ElementType>();
ll.init(ElementType, ['data1', 'data2', 'data3']);
ll.addElem('data4');
Add an element at the right of the list, alias of addElemRight
var ll:LinkedList<ElementType> = new LinkedList<ElementType>();
ll.init(ElementType, ['data1', 'data2', 'data3']);
ll.addElemRight('data4');
Add an element at the right of the list
var ll:LinkedList<ElementType> = new LinkedList<ElementType>();
ll.init(ElementType, ['data1', 'data2', 'data3']);
ll.addElemLeft('data4');
Add an element at the left of the list
var ll:LinkedList<ElementType> = new LinkedList<ElementType>();
ll.init(ElementType, ['data1', 'data2', 'data3']);
//
var listElem:ElemenType = ll.get();
ll.removeElem(listElem);
//
// or
//
ll.removeElem();
Remove current element or a specified one
var ll:LinkedList<ElementType> = new LinkedList<ElementType>();
ll.init(ElementType, ['data1', 'data2', 'data3']);
ll.removeElemByPos(1);
Remove element by position in the list
var ll:LinkedList<ElementType> = new LinkedList<ElementType>();
ll.init(ElementType, ['data1', 'data2', 'data3']);
ll.removeElemByData('data2');
Remove element by data
var ll:LinkedList<ElementType> = new LinkedList<ElementType>();
ll.init(ElementType, ['data1', 'data2', 'data3']);
ll.insertElem('data2', 1);
Add element at the specified position, without position the element will be added at the start of the list like addElemLeft`
var ll:LinkedList<ElementType> = new LinkedList<ElementType>();
ll.init(ElementType, ['data1', 'data2', 'data3']);
ll.length(); // return 3
Return the length of the list
var ll:LinkedList<ElementType> = new LinkedList<ElementType>();
ll.init(ElementType, ['data1', 'data2', 'data3']);
ll.toStart();
Move the internal pointer to the head of the list
var ll:LinkedList<ElementType> = new LinkedList<ElementType>();
ll.init(ElementType, ['data1', 'data2', 'data3']);
ll.toNext();
Move the internal pointer to the next element with rispect to the current element
var ll:LinkedList<ElementType> = new LinkedList<ElementType>();
ll.init(ElementType, ['data1', 'data2', 'data3']);
ll.toPrev();
Move the internal pointer to the previous element with rispect to the current element
var ll:LinkedList<ElementType> = new LinkedList<ElementType>();
ll.init(ElementType, ['data1', 'data2', 'data3']);
ll.toEnd();
Move the internal pointer to the end of the list
var ll:LinkedList<ElementType> = new LinkedList<ElementType>();
ll.init(ElementType, ['data1', 'data2', 'data3']);
ll.get();
Return the current element
var ll:LinkedList<ElementType> = new LinkedList<ElementType>();
ll.init(ElementType, ['data1', 'data2', 'data3']);
//
var listElem:ElemenType = ll.toNext().get();
ll.isStart(listElem);
Check if the passed element is the head of the list
var ll:LinkedList<ElementType> = new LinkedList<ElementType>();
ll.init(ElementType, ['data1', 'data2', 'data3']);
//
var listElem:ElemenType = ll.toNext().get();
ll.isStart(listElem);
Check if the passed element is the end of the list
var ll:LinkedList<ElementType> = new LinkedList<ElementType>();
ll.init(ElementType, ['data1', 'data2', 'data3']);
ll.clone();
//
// or
//
var ll_cloned:LinkedList<ElementType> = ll.clone(true);
Clones the list, by default the reference of the cloned list will be stored in the cloned_list
, if true value will be passed the refence will return directly
var ll1:LinkedList<ElementType> = new LinkedList<ElementType>();
ll1.init(ElementType, ['data1', 'data2', 'data3']);
//
var ll2:LinkedList<ElementType> = new LinkedList<ElementType>();
ll2.init(ElementType, ['data4', 'data5', 'data6']);
//
ll1.concat(ll2);
Concatenate two lists
var ll1:LinkedList<ElementType> = new LinkedList<ElementType>();
ll1.init(ElementType, ['data1', 'data2', 'data3']);
//
var ll2:LinkedList<ElementType> = new LinkedList<ElementType>();
ll2.init(ElementType, ['data4', 'data5', 'data6']);
//
ll1.rMerge(ll2);
Merge recursively two lists, a sorting func can be passed
var ll1:LinkedList<ElementType> = new LinkedList<ElementType>();
ll1.init(ElementType, ['data1', 'data2', 'data3']);
//
var ll2:LinkedList<ElementType> = new LinkedList<ElementType>();
ll2.init(ElementType, ['data4', 'data5', 'data6']);
//
ll1.merge(ll2);
Merge two lists, a sorting func can be passed // TODO
var ll:LinkedList<ElementType> = new LinkedList<ElementType>();
ll.init(ElementType, ['data1', 'data2', 'data3']);
var arr_to_list:Array\<any\> = ll.toArray();
Return an array with value from the list's elements
var ll:LinkedList<ElementType> = new LinkedList<ElementType>();
ll.init(ElementType, [7, 5, 3, 9, 12, 0]);
ll.rSort();
Sort recursively the list, a sorting function an the list to sort can be passed
var ll:LinkedList<ElementType> = new LinkedList<ElementType>();
ll.init(ElementType, [7, 5, 3, 9, 12, 0]);
ll.rSort();
Sort the list, a sorting function an the list to sort can be passed `// TODO
var ll1:LinkedList<ElementType> = new LinkedList<ElementType>();
ll1.init(ElementType, ['data1', 'data2', 'data3']);
//
var ll2:LinkedList<ElementType> = new LinkedList<ElementType>();
ll2.init(ElementType, ['data1', 'data5', 'data3']);
//
ll1.isEqual(ll2);
Check if the list is equal to another, compare function can be passed
var ll:LinkedList<ElementType> = new LinkedList<ElementType>();
ll.init(ElementType, [7, 5, 3, 9, 12, 0]);
ll.destroy();
Destroy the list