@raikuxq/alg-ds 1.1.2 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -2
- package/lib/algorithms/binary-search.d.ts +5 -0
- package/lib/algorithms/binary-search.js +27 -0
- package/lib/algorithms/factorial.d.ts +9 -0
- package/lib/algorithms/factorial.js +17 -0
- package/lib/algorithms/fibonacci.d.ts +9 -0
- package/lib/algorithms/fibonacci.js +17 -0
- package/lib/algorithms/memoize.d.ts +5 -0
- package/lib/algorithms/memoize.js +22 -0
- package/lib/algorithms/sorts/bubble-sort.d.ts +9 -0
- package/lib/algorithms/sorts/bubble-sort.js +23 -0
- package/lib/algorithms/sorts/insertion-sort.d.ts +9 -0
- package/lib/algorithms/sorts/insertion-sort.js +25 -0
- package/lib/algorithms/sorts/merge-sort.d.ts +9 -0
- package/lib/algorithms/sorts/merge-sort.js +61 -0
- package/lib/algorithms/sorts/quick-sort.d.ts +9 -0
- package/lib/algorithms/sorts/quick-sort.js +45 -0
- package/lib/algorithms/sorts/select-sort.d.ts +9 -0
- package/lib/algorithms/sorts/select-sort.js +20 -0
- package/lib/algorithms/transpose-matrix.d.ts +5 -0
- package/lib/algorithms/transpose-matrix.js +20 -0
- package/lib/constants.d.ts +2 -0
- package/lib/constants.js +6 -0
- package/lib/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryNode.d.ts +15 -0
- package/lib/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryNode.js +53 -0
- package/lib/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryTree.d.ts +60 -0
- package/lib/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryTree.js +36 -0
- package/lib/data-structures/BinaryTree/BinarySearchTree/BinarySearchNode.d.ts +13 -0
- package/lib/data-structures/BinaryTree/BinarySearchTree/BinarySearchNode.js +59 -0
- package/lib/data-structures/BinaryTree/BinarySearchTree/BinarySearchTree.d.ts +70 -0
- package/lib/data-structures/BinaryTree/BinarySearchTree/BinarySearchTree.js +268 -0
- package/lib/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchNode.d.ts +16 -0
- package/lib/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchNode.js +70 -0
- package/lib/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchTree.d.ts +57 -0
- package/lib/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchTree.js +234 -0
- package/lib/data-structures/Graph/AbstractGraph.d.ts +84 -0
- package/lib/data-structures/Graph/AbstractGraph.js +141 -0
- package/lib/data-structures/Graph/DirectedGraph.d.ts +24 -0
- package/lib/data-structures/Graph/DirectedGraph.js +85 -0
- package/lib/data-structures/Graph/GraphEdge.d.ts +16 -0
- package/lib/data-structures/Graph/GraphEdge.js +43 -0
- package/lib/data-structures/Graph/UndirectedGraph.d.ts +28 -0
- package/lib/data-structures/Graph/UndirectedGraph.js +102 -0
- package/lib/data-structures/Graph/demo/generateRandomGraph.d.ts +4 -0
- package/lib/data-structures/Graph/demo/generateRandomGraph.js +72 -0
- package/lib/data-structures/Graph/iterator/AbstractGraphIterator.d.ts +35 -0
- package/lib/data-structures/Graph/iterator/AbstractGraphIterator.js +90 -0
- package/lib/data-structures/Graph/iterator/GraphIteratorBFS.d.ts +28 -0
- package/lib/data-structures/Graph/iterator/GraphIteratorBFS.js +70 -0
- package/lib/data-structures/Graph/iterator/GraphIteratorDFS.d.ts +28 -0
- package/lib/data-structures/Graph/iterator/GraphIteratorDFS.js +70 -0
- package/lib/data-structures/Graph/iterator/GraphIteratorDijkstra.d.ts +32 -0
- package/lib/data-structures/Graph/iterator/GraphIteratorDijkstra.js +99 -0
- package/lib/data-structures/Graph/presenter/presenterAdjacencyLists.d.ts +19 -0
- package/lib/data-structures/Graph/presenter/presenterAdjacencyLists.js +28 -0
- package/{src/data-structures/Graph/presenter/presenterAdjacencyMatrix.ts → lib/data-structures/Graph/presenter/presenterAdjacencyMatrix.d.ts} +32 -51
- package/lib/data-structures/Graph/presenter/presenterAdjacencyMatrix.js +48 -0
- package/lib/data-structures/Graph/searching/hasPath.d.ts +9 -0
- package/lib/data-structures/Graph/searching/hasPath.js +29 -0
- package/lib/data-structures/Graph/searching/shortestPath.d.ts +9 -0
- package/lib/data-structures/Graph/searching/shortestPath.js +29 -0
- package/lib/data-structures/Graph/strategy/BFSIterationStrategy.d.ts +6 -0
- package/lib/data-structures/Graph/strategy/BFSIterationStrategy.js +13 -0
- package/lib/data-structures/Graph/strategy/DFSIterationStrategy.d.ts +6 -0
- package/lib/data-structures/Graph/strategy/DFSIterationStrategy.js +13 -0
- package/lib/data-structures/Graph/strategy/DijkstraIterationStrategy.d.ts +6 -0
- package/lib/data-structures/Graph/strategy/DijkstraIterationStrategy.js +13 -0
- package/lib/data-structures/Graph/transposing/transposeDirectedGraph.d.ts +2 -0
- package/lib/data-structures/Graph/transposing/transposeDirectedGraph.js +14 -0
- package/lib/data-structures/HashTable/HashTable.d.ts +73 -0
- package/lib/data-structures/HashTable/HashTable.js +169 -0
- package/lib/data-structures/HashTable/HashTableNode.d.ts +11 -0
- package/lib/data-structures/HashTable/HashTableNode.js +39 -0
- package/lib/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedList.d.ts +125 -0
- package/lib/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedList.js +236 -0
- package/lib/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedNode.d.ts +20 -0
- package/lib/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedNode.js +41 -0
- package/lib/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedList.d.ts +48 -0
- package/lib/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedList.js +150 -0
- package/lib/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedNode.d.ts +25 -0
- package/lib/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedNode.js +65 -0
- package/lib/data-structures/LinkedList/SingleLinkedList/SingleLinkedList.d.ts +52 -0
- package/lib/data-structures/LinkedList/SingleLinkedList/SingleLinkedList.js +137 -0
- package/{src/data-structures/LinkedList/SingleLinkedList/SingleLinkedNode.ts → lib/data-structures/LinkedList/SingleLinkedList/SingleLinkedNode.d.ts} +7 -10
- package/lib/data-structures/LinkedList/SingleLinkedList/SingleLinkedNode.js +29 -0
- package/lib/data-structures/LoopedArray/LoopedArray.d.ts +86 -0
- package/lib/data-structures/LoopedArray/LoopedArray.js +161 -0
- package/lib/data-structures/Queue/Queue.d.ts +50 -0
- package/lib/data-structures/Queue/Queue.js +83 -0
- package/lib/data-structures/Stack/Stack.d.ts +50 -0
- package/lib/data-structures/Stack/Stack.js +83 -0
- package/lib/exports/algorithms.d.ts +16 -0
- package/lib/exports/algorithms.js +36 -0
- package/lib/exports/constants.d.ts +2 -0
- package/lib/exports/constants.js +7 -0
- package/lib/exports/data-structures.d.ts +11 -0
- package/lib/exports/data-structures.js +24 -0
- package/lib/exports/helpers.d.ts +6 -0
- package/lib/exports/helpers.js +14 -0
- package/lib/exports/sorts.d.ts +6 -0
- package/lib/exports/sorts.js +14 -0
- package/lib/exports/utils.d.ts +3 -0
- package/lib/exports/utils.js +14 -0
- package/lib/exports.d.ts +44 -0
- package/lib/exports.js +89 -0
- package/lib/helpers/createBinaryTree.d.ts +6 -0
- package/lib/helpers/createBinaryTree.js +22 -0
- package/lib/helpers/createGraph.d.ts +6 -0
- package/lib/helpers/createGraph.js +24 -0
- package/lib/helpers/createGraphFromMatrix.d.ts +7 -0
- package/lib/helpers/createGraphFromMatrix.js +37 -0
- package/lib/helpers/createLinkedList.d.ts +3 -0
- package/lib/helpers/createLinkedList.js +21 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +6 -0
- package/lib/types/ArrayMatrix.d.ts +1 -0
- package/lib/types/ArrayMatrix.js +3 -0
- package/lib/types/EnumBinarySearchTreeType.d.ts +4 -0
- package/lib/types/EnumBinarySearchTreeType.js +9 -0
- package/lib/types/EnumGraphType.d.ts +4 -0
- package/lib/types/EnumGraphType.js +9 -0
- package/lib/types/EnumLinkedListType.d.ts +4 -0
- package/lib/types/EnumLinkedListType.js +9 -0
- package/lib/types/EnumRandomGenerationFormat.d.ts +4 -0
- package/lib/types/EnumRandomGenerationFormat.js +9 -0
- package/lib/types/EnumTreeTraversalType.d.ts +5 -0
- package/lib/types/EnumTreeTraversalType.js +10 -0
- package/lib/types/FnCompareTwo.d.ts +1 -0
- package/lib/types/FnCompareTwo.js +3 -0
- package/lib/types/FnToMemoize.d.ts +1 -0
- package/lib/types/FnToMemoize.js +3 -0
- package/{src/types/ILinkedList.ts → lib/types/IArrayFacade.d.ts} +4 -6
- package/lib/types/IArrayFacade.js +3 -0
- package/{src/types/IBiDirectIterable.ts → lib/types/IBiDirectIterable.d.ts} +5 -6
- package/lib/types/IBiDirectIterable.js +3 -0
- package/lib/types/IBiDirectIterator.d.ts +11 -0
- package/lib/types/IBiDirectIterator.js +3 -0
- package/lib/types/IBinaryTree.d.ts +12 -0
- package/lib/types/IBinaryTree.js +3 -0
- package/lib/types/IConvertableToArray.d.ts +4 -0
- package/lib/types/IConvertableToArray.js +3 -0
- package/lib/types/IGraph.d.ts +14 -0
- package/lib/types/IGraph.js +3 -0
- package/{src/types/IGraphIterationStrategy.ts → lib/types/IGraphIterationStrategy.d.ts} +5 -6
- package/lib/types/IGraphIterationStrategy.js +3 -0
- package/lib/types/IGraphIterator.d.ts +11 -0
- package/lib/types/IGraphIterator.js +3 -0
- package/{src/types/IIterable.ts → lib/types/IIterable.d.ts} +4 -5
- package/lib/types/IIterable.js +3 -0
- package/lib/types/IIterator.d.ts +14 -0
- package/lib/types/IIterator.js +3 -0
- package/lib/types/IKeyValueStorage.d.ts +8 -0
- package/lib/types/IKeyValueStorage.js +3 -0
- package/lib/types/ILinearStorage.d.ts +11 -0
- package/lib/types/ILinearStorage.js +3 -0
- package/{src/types/ILinearStorageRA.ts → lib/types/ILinearStorageRA.d.ts} +13 -14
- package/lib/types/ILinearStorageRA.js +3 -0
- package/{src/types/IArrayFacade.ts → lib/types/ILinkedList.d.ts} +4 -6
- package/lib/types/ILinkedList.js +3 -0
- package/lib/utils.d.ts +29 -0
- package/lib/utils.js +95 -0
- package/package.json +9 -3
- package/.idea/algorythmes.iml +0 -15
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/deployment.xml +0 -14
- package/.idea/inspectionProfiles/Project_Default.xml +0 -7
- package/.idea/jsLinters/eslint.xml +0 -6
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/lib/algotirhms.ts +0 -35
- package/lib/constants.ts +0 -3
- package/lib/data-structures.ts +0 -23
- package/lib/helpers.ts +0 -13
- package/lib/sorts.ts +0 -7
- package/lib/types.ts +0 -53
- package/lib/utils.ts +0 -21
- package/src/algorithms/binary-search.ts +0 -28
- package/src/algorithms/factorial.ts +0 -18
- package/src/algorithms/fibonacci.ts +0 -18
- package/src/algorithms/memoize.ts +0 -21
- package/src/algorithms/sorts/bubble-sort.ts +0 -21
- package/src/algorithms/sorts/insertion-sort.ts +0 -25
- package/src/algorithms/sorts/merge-sort.ts +0 -74
- package/src/algorithms/sorts/quick-sort.ts +0 -54
- package/src/algorithms/sorts/select-sort.ts +0 -19
- package/src/algorithms/transpose-matrix.ts +0 -19
- package/src/constants.ts +0 -2
- package/src/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryNode.ts +0 -45
- package/src/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryTree.ts +0 -80
- package/src/data-structures/BinaryTree/BinarySearchTree/BinarySearchNode.ts +0 -38
- package/src/data-structures/BinaryTree/BinarySearchTree/BinarySearchTree.ts +0 -286
- package/src/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchNode.ts +0 -48
- package/src/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchTree.ts +0 -228
- package/src/data-structures/Graph/AbstractGraph.ts +0 -189
- package/src/data-structures/Graph/DirectedGraph.ts +0 -84
- package/src/data-structures/Graph/GraphEdge.ts +0 -33
- package/src/data-structures/Graph/UndirectedGraph.ts +0 -108
- package/src/data-structures/Graph/demo/generateRandomGraph.ts +0 -93
- package/src/data-structures/Graph/iterator/AbstractGraphIterator.ts +0 -99
- package/src/data-structures/Graph/iterator/GraphIteratorBFS.ts +0 -60
- package/src/data-structures/Graph/iterator/GraphIteratorDFS.ts +0 -60
- package/src/data-structures/Graph/iterator/GraphIteratorDijkstra.ts +0 -94
- package/src/data-structures/Graph/presenter/presenterAdjacencyLists.ts +0 -29
- package/src/data-structures/Graph/searching/hasPath.ts +0 -38
- package/src/data-structures/Graph/searching/shortestPath.ts +0 -38
- package/src/data-structures/Graph/strategy/BFSIterationStrategy.ts +0 -11
- package/src/data-structures/Graph/strategy/DFSIterationStrategy.ts +0 -11
- package/src/data-structures/Graph/strategy/DijkstraIterationStrategy.ts +0 -11
- package/src/data-structures/Graph/transposing/transposeDirectedGraph.ts +0 -19
- package/src/data-structures/HashTable/HashTable.ts +0 -202
- package/src/data-structures/HashTable/HashTableNode.ts +0 -31
- package/src/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedList.ts +0 -310
- package/src/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedNode.ts +0 -33
- package/src/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedList.ts +0 -156
- package/src/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedNode.ts +0 -47
- package/src/data-structures/LinkedList/SingleLinkedList/SingleLinkedList.ts +0 -147
- package/src/data-structures/LoopedArray/LoopedArray.ts +0 -182
- package/src/data-structures/Queue/Queue.ts +0 -92
- package/src/data-structures/Stack/Stack.ts +0 -92
- package/src/demo/demo.bst.ts +0 -67
- package/src/demo/demo.graph.ts +0 -246
- package/src/demo/demo.hashtable.ts +0 -28
- package/src/demo/demo.linked-list.ts +0 -78
- package/src/demo/demo.looped-array.ts +0 -104
- package/src/demo/demo.queue.ts +0 -40
- package/src/demo/demo.stack.ts +0 -40
- package/src/demo/performance/bst-compare.ts +0 -35
- package/src/demo/performance/ds-compare.ts +0 -58
- package/src/demo/performance/hash-table.compare.ts +0 -40
- package/src/demo/performance/sort-compare.ts +0 -60
- package/src/helpers/createBinaryTree.ts +0 -24
- package/src/helpers/createGraph.ts +0 -24
- package/src/helpers/createGraphFromMatrix.ts +0 -47
- package/src/helpers/createLinkedList.ts +0 -24
- package/src/index.ts +0 -44
- package/src/types/ArrayMatrix.ts +0 -1
- package/src/types/EnumBinarySearchTreeType.ts +0 -4
- package/src/types/EnumGraphTraversalType.ts +0 -5
- package/src/types/EnumGraphType.ts +0 -4
- package/src/types/EnumLinkedListType.ts +0 -4
- package/src/types/EnumRandomGenerationFormat.ts +0 -4
- package/src/types/EnumSortType.ts +0 -7
- package/src/types/EnumTreeTraversalType.ts +0 -5
- package/src/types/FnCompareTwo.ts +0 -1
- package/src/types/FnSort.ts +0 -1
- package/src/types/FnToMemoize.ts +0 -1
- package/src/types/IBiDirectIterator.ts +0 -12
- package/src/types/IBinaryTree.ts +0 -13
- package/src/types/IConvertableToArray.ts +0 -4
- package/src/types/IGraph.ts +0 -16
- package/src/types/IGraphCreator.ts +0 -5
- package/src/types/IGraphIterator.ts +0 -13
- package/src/types/IIterator.ts +0 -14
- package/src/types/IKeyValueStorage.ts +0 -8
- package/src/types/ILinearStorage.ts +0 -11
- package/src/utils.ts +0 -65
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
import AbstractLinkedNode from "./AbstractLinkedNode";
|
|
2
|
-
import ILinkedList from "../../../types/ILinkedList";
|
|
3
|
-
|
|
4
|
-
export default abstract class AbstractLinkedList<T> implements ILinkedList<T> {
|
|
5
|
-
protected readonly _capacity: number;
|
|
6
|
-
protected _length: number;
|
|
7
|
-
protected _head: AbstractLinkedNode<T> | null;
|
|
8
|
-
protected _tail: AbstractLinkedNode<T> | null;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Create empty instance
|
|
12
|
-
*/
|
|
13
|
-
protected constructor(capacity?: number) {
|
|
14
|
-
this._capacity = AbstractLinkedList.calculateCapacity(capacity);
|
|
15
|
-
this._head = null;
|
|
16
|
-
this._tail = null;
|
|
17
|
-
this._length = 0;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Will calculate real capacity value
|
|
22
|
-
* @throws when capacity <= 0
|
|
23
|
-
*/
|
|
24
|
-
private static calculateCapacity(capacity?: number) {
|
|
25
|
-
if (capacity === undefined) {
|
|
26
|
-
return Number.MAX_VALUE;
|
|
27
|
-
}
|
|
28
|
-
if (capacity <= 0) {
|
|
29
|
-
throw new Error("Capacity must be larger than 0");
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return capacity;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Will insert node between nodeLeft and nodeRight
|
|
37
|
-
* @throws when list is full
|
|
38
|
-
*/
|
|
39
|
-
private insertNodeBetweenTwoNodes(
|
|
40
|
-
targetNode: AbstractLinkedNode<T>,
|
|
41
|
-
leftNode: AbstractLinkedNode<T> | null,
|
|
42
|
-
rightNode: AbstractLinkedNode<T> | null
|
|
43
|
-
): void {
|
|
44
|
-
if (this.isFull()) {
|
|
45
|
-
throw new Error("List is full, no more space available");
|
|
46
|
-
}
|
|
47
|
-
if (this._head === null) {
|
|
48
|
-
this._head = targetNode;
|
|
49
|
-
}
|
|
50
|
-
if (this._tail === null) {
|
|
51
|
-
this._tail = targetNode;
|
|
52
|
-
}
|
|
53
|
-
if (!leftNode) {
|
|
54
|
-
leftNode = this._tail;
|
|
55
|
-
}
|
|
56
|
-
if (!rightNode) {
|
|
57
|
-
rightNode = this._head;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
this.insertNodeBetweenTwoNodesImpl(targetNode, leftNode, rightNode);
|
|
61
|
-
this._length++;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Will remove the node from its neighbors nodes links
|
|
66
|
-
* @throws when node does not exist
|
|
67
|
-
*/
|
|
68
|
-
private deleteNode(
|
|
69
|
-
node: AbstractLinkedNode<T> | null
|
|
70
|
-
): AbstractLinkedNode<T> {
|
|
71
|
-
if (node === null) {
|
|
72
|
-
throw new Error("Node should be existed");
|
|
73
|
-
}
|
|
74
|
-
this.deleteNodeImpl(node);
|
|
75
|
-
this._length--;
|
|
76
|
-
|
|
77
|
-
if (this.isEmpty()) {
|
|
78
|
-
this.clear();
|
|
79
|
-
}
|
|
80
|
-
return node;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Will find node by its index
|
|
85
|
-
* @throws when node was not found
|
|
86
|
-
*/
|
|
87
|
-
protected getNodeByIndex(index: number): AbstractLinkedNode<T> {
|
|
88
|
-
if (this.isEmpty()) {
|
|
89
|
-
throw new Error("List is empty");
|
|
90
|
-
}
|
|
91
|
-
if (this._length < index) {
|
|
92
|
-
throw new Error("Index exceed list length");
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
let currentNode = this._tail;
|
|
96
|
-
let counter = 0;
|
|
97
|
-
|
|
98
|
-
while (currentNode && counter < index) {
|
|
99
|
-
currentNode = currentNode.next;
|
|
100
|
-
counter++;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (currentNode === null) {
|
|
104
|
-
throw new Error("Node does not exist");
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return currentNode;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Will set links between target, left and right siblings
|
|
112
|
-
*/
|
|
113
|
-
protected abstract insertNodeBetweenTwoNodesImpl(
|
|
114
|
-
nodeToPush: AbstractLinkedNode<T>,
|
|
115
|
-
nodeLeft: AbstractLinkedNode<T>,
|
|
116
|
-
nodeRight: AbstractLinkedNode<T>
|
|
117
|
-
): void;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Will unset itself links and its neighbors links
|
|
121
|
-
*/
|
|
122
|
-
protected abstract deleteNodeImpl(node: AbstractLinkedNode<T>): void;
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Update head link
|
|
126
|
-
*/
|
|
127
|
-
protected abstract popImpl(): void;
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Update tail link
|
|
131
|
-
*/
|
|
132
|
-
protected abstract shiftImpl(): void;
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Will create empty node instance
|
|
136
|
-
*/
|
|
137
|
-
protected abstract createNode(value: T): AbstractLinkedNode<T>;
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Push into start
|
|
141
|
-
*/
|
|
142
|
-
public unshift(value: T): void {
|
|
143
|
-
const node = this.createNode(value);
|
|
144
|
-
this.insertNodeBetweenTwoNodes(node, this._head, this._tail);
|
|
145
|
-
this._tail = node;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Push into end
|
|
150
|
-
*/
|
|
151
|
-
public push(value: T): void {
|
|
152
|
-
const node = this.createNode(value);
|
|
153
|
-
this.insertNodeBetweenTwoNodes(node, this._head, this._tail);
|
|
154
|
-
this._head = node;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Push from index
|
|
159
|
-
*/
|
|
160
|
-
public pushFromIndex(value: T, fromIndex: number): void {
|
|
161
|
-
const isIndexNotInRange = fromIndex < 0 || fromIndex > this._length;
|
|
162
|
-
const shouldPushAsFirst = this.isEmpty() && fromIndex === 0;
|
|
163
|
-
|
|
164
|
-
if (isIndexNotInRange) {
|
|
165
|
-
throw new Error("index must be in range between 0 and list length");
|
|
166
|
-
}
|
|
167
|
-
if (shouldPushAsFirst) {
|
|
168
|
-
this.push(value);
|
|
169
|
-
} else {
|
|
170
|
-
const node = this.createNode(value);
|
|
171
|
-
const nodeLeft = this.getNodeByIndex(fromIndex - 1);
|
|
172
|
-
const nodeRight = this.getNodeByIndex(fromIndex);
|
|
173
|
-
this.insertNodeBetweenTwoNodes(node, nodeLeft, nodeRight);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Delete node from list's end
|
|
179
|
-
*/
|
|
180
|
-
public pop(): T {
|
|
181
|
-
const deletedNode = this.deleteNode(this._head);
|
|
182
|
-
this.popImpl();
|
|
183
|
-
return deletedNode.data;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Delete node from list's start and get its data
|
|
188
|
-
*/
|
|
189
|
-
public shift(): T {
|
|
190
|
-
const deletedNode = this.deleteNode(this._tail);
|
|
191
|
-
this.shiftImpl();
|
|
192
|
-
return deletedNode.data;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Delete node from list by index from start
|
|
197
|
-
*/
|
|
198
|
-
public deleteFromIndex(fromIndex: number): T {
|
|
199
|
-
const nodeToDelete = this.getNodeByIndex(fromIndex);
|
|
200
|
-
const deletedNode = this.deleteNode(nodeToDelete);
|
|
201
|
-
return deletedNode.data;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* List length
|
|
206
|
-
*/
|
|
207
|
-
public length(): number {
|
|
208
|
-
return this._length;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Is list empty
|
|
213
|
-
*/
|
|
214
|
-
public isEmpty(): boolean {
|
|
215
|
-
return this._length === 0;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Is list full
|
|
220
|
-
*/
|
|
221
|
-
public isFull(): boolean {
|
|
222
|
-
return this._length >= this._capacity;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Check if element exists in list
|
|
227
|
-
*/
|
|
228
|
-
public has(item: T): boolean {
|
|
229
|
-
return this.getAsArray().includes(item);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Get head element data
|
|
234
|
-
* @throws Error when head does not exist
|
|
235
|
-
*/
|
|
236
|
-
public peek(): T {
|
|
237
|
-
if (!this._head) {
|
|
238
|
-
throw new Error("Head does not exist");
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
return this._head.data;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Get tail element data
|
|
246
|
-
* @throws Error when tail does not exists
|
|
247
|
-
*/
|
|
248
|
-
public peekFromStart(): T {
|
|
249
|
-
if (!this._tail) {
|
|
250
|
-
throw new Error("Tail does not exist");
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
return this._tail.data;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Get list element by index from start
|
|
258
|
-
* @throws when element does not exist
|
|
259
|
-
*/
|
|
260
|
-
public peekByIndex(index: number): T {
|
|
261
|
-
const node = this.getNodeByIndex(index);
|
|
262
|
-
return node.data;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Remove all elements from list
|
|
267
|
-
*/
|
|
268
|
-
public clear(): void {
|
|
269
|
-
this._head = null;
|
|
270
|
-
this._tail = null;
|
|
271
|
-
this._length = 0;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Get elements as an array
|
|
276
|
-
*/
|
|
277
|
-
public getAsArray(): Array<T> {
|
|
278
|
-
const array: Array<T> = [];
|
|
279
|
-
let currentNode = this._tail;
|
|
280
|
-
let counter = 0;
|
|
281
|
-
|
|
282
|
-
while (currentNode && counter < this._length) {
|
|
283
|
-
if (currentNode) array.push(currentNode.data);
|
|
284
|
-
|
|
285
|
-
currentNode = currentNode.next;
|
|
286
|
-
counter++;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
return array;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Add elements to list from array
|
|
294
|
-
* @throws when list is full
|
|
295
|
-
* */
|
|
296
|
-
public pushFromArray(elements: Array<T>): void {
|
|
297
|
-
elements.forEach((element: T) => {
|
|
298
|
-
if (this.isFull()) {
|
|
299
|
-
throw new Error("List is full, no more space available");
|
|
300
|
-
}
|
|
301
|
-
this.push(element);
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Reverse list nodes links and swap head with tail
|
|
307
|
-
* @example "4>7>10" will be reversed to "10>7>4"
|
|
308
|
-
*/
|
|
309
|
-
public abstract reverse(): void;
|
|
310
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export default abstract class AbstractLinkedNode<T> {
|
|
2
|
-
protected _next: AbstractLinkedNode<T> | null;
|
|
3
|
-
protected readonly _data: T;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Will create empty node
|
|
7
|
-
*/
|
|
8
|
-
protected constructor(data: T, next: AbstractLinkedNode<T> | null = null) {
|
|
9
|
-
this._data = data;
|
|
10
|
-
this._next = next;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Get data of node
|
|
15
|
-
*/
|
|
16
|
-
public get data(): T {
|
|
17
|
-
return this._data;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Get next node link
|
|
22
|
-
*/
|
|
23
|
-
public get next(): AbstractLinkedNode<T> | null {
|
|
24
|
-
return this._next;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Set next node link
|
|
29
|
-
*/
|
|
30
|
-
public set next(value: AbstractLinkedNode<T> | null) {
|
|
31
|
-
this._next = value;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import IBiDirectIterator from "../../../types/IBiDirectIterator";
|
|
2
|
-
import IBiDirectIterable from "../../../types/IBiDirectIterable";
|
|
3
|
-
import AbstractLinkedList from "../AbstractLinkedList/AbstractLinkedList";
|
|
4
|
-
import DoubleLinkedNode from "./DoubleLinkedNode";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Linear data structure
|
|
8
|
-
* Each node has next and prev sibling
|
|
9
|
-
* Head and tail are linked to each other
|
|
10
|
-
*/
|
|
11
|
-
export default class DoubleLinkedList<T>
|
|
12
|
-
extends AbstractLinkedList<T>
|
|
13
|
-
implements IBiDirectIterable<T> {
|
|
14
|
-
/**
|
|
15
|
-
* Override types
|
|
16
|
-
*/
|
|
17
|
-
protected _head: DoubleLinkedNode<T> | null;
|
|
18
|
-
protected _tail: DoubleLinkedNode<T> | null;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @inheritDoc
|
|
22
|
-
*/
|
|
23
|
-
public constructor(capacity?: number) {
|
|
24
|
-
super(capacity);
|
|
25
|
-
this._head = null;
|
|
26
|
-
this._tail = null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @inheritDoc
|
|
31
|
-
*/
|
|
32
|
-
protected createNode(value: T): DoubleLinkedNode<T> {
|
|
33
|
-
return new DoubleLinkedNode<T>(value);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @inheritDoc
|
|
38
|
-
*/
|
|
39
|
-
protected insertNodeBetweenTwoNodesImpl(
|
|
40
|
-
targetNode: DoubleLinkedNode<T>,
|
|
41
|
-
leftNode: DoubleLinkedNode<T>,
|
|
42
|
-
rightNode: DoubleLinkedNode<T>
|
|
43
|
-
): void {
|
|
44
|
-
targetNode.next = rightNode;
|
|
45
|
-
targetNode.prev = leftNode;
|
|
46
|
-
|
|
47
|
-
if (targetNode.prev) {
|
|
48
|
-
targetNode.prev.next = targetNode;
|
|
49
|
-
}
|
|
50
|
-
if (targetNode.next) {
|
|
51
|
-
targetNode.next.prev = targetNode;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @inheritDoc
|
|
57
|
-
*/
|
|
58
|
-
protected deleteNodeImpl(node: DoubleLinkedNode<T>): void {
|
|
59
|
-
node!.prev!.next = node!.next;
|
|
60
|
-
node!.next!.prev = node!.prev;
|
|
61
|
-
node!.next = null;
|
|
62
|
-
node!.prev = null;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* @inheritDoc
|
|
67
|
-
*/
|
|
68
|
-
protected popImpl(): void {
|
|
69
|
-
this._head = this._tail?.prev || null;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* @inheritDoc
|
|
74
|
-
*/
|
|
75
|
-
protected shiftImpl(): void {
|
|
76
|
-
this._tail = this._head?.next || null;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* @inheritDoc
|
|
81
|
-
*/
|
|
82
|
-
public reverse(): void {
|
|
83
|
-
let currentNode = this._tail;
|
|
84
|
-
let i = 0;
|
|
85
|
-
|
|
86
|
-
while (currentNode && i < this._length) {
|
|
87
|
-
const newPrev = currentNode.next;
|
|
88
|
-
const newNext = currentNode.prev;
|
|
89
|
-
|
|
90
|
-
currentNode.prev = newPrev;
|
|
91
|
-
currentNode.next = newNext;
|
|
92
|
-
|
|
93
|
-
i++;
|
|
94
|
-
currentNode = newNext;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (currentNode) {
|
|
98
|
-
this._tail = currentNode.next;
|
|
99
|
-
this._head = currentNode;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* List iterator
|
|
105
|
-
*/
|
|
106
|
-
public iterator(fromIndex = 0): IBiDirectIterator<T> {
|
|
107
|
-
const head = this._head;
|
|
108
|
-
const tail = this._tail;
|
|
109
|
-
let activeNode = this.getNodeByIndex(fromIndex) as DoubleLinkedNode<T>;
|
|
110
|
-
|
|
111
|
-
const iterator: IBiDirectIterator<T> = {
|
|
112
|
-
/**
|
|
113
|
-
* @inheritDoc
|
|
114
|
-
*/
|
|
115
|
-
current: () => {
|
|
116
|
-
return activeNode.data;
|
|
117
|
-
},
|
|
118
|
-
/**
|
|
119
|
-
* @inheritDoc
|
|
120
|
-
*/
|
|
121
|
-
hasNext(): boolean {
|
|
122
|
-
return Boolean(activeNode.next) && activeNode !== head;
|
|
123
|
-
},
|
|
124
|
-
/**
|
|
125
|
-
* @inheritDoc
|
|
126
|
-
*/
|
|
127
|
-
hasPrev(): boolean {
|
|
128
|
-
return Boolean(activeNode.prev) && activeNode !== tail;
|
|
129
|
-
},
|
|
130
|
-
/**
|
|
131
|
-
* @inheritDoc
|
|
132
|
-
* @throws when next element does not exist
|
|
133
|
-
*/
|
|
134
|
-
next: (): T => {
|
|
135
|
-
if (!iterator.hasNext()) {
|
|
136
|
-
throw new Error("Next element does not exist");
|
|
137
|
-
}
|
|
138
|
-
activeNode = activeNode.next!;
|
|
139
|
-
return activeNode.data;
|
|
140
|
-
},
|
|
141
|
-
/**
|
|
142
|
-
* @inheritDoc
|
|
143
|
-
* @throws when prev element does not exists
|
|
144
|
-
*/
|
|
145
|
-
prev: (): T => {
|
|
146
|
-
if (!iterator.hasPrev()) {
|
|
147
|
-
throw new Error("Prev element does not exist");
|
|
148
|
-
}
|
|
149
|
-
activeNode = activeNode.prev!;
|
|
150
|
-
return activeNode.data;
|
|
151
|
-
},
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
return iterator;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import AbstractLinkedNode from "../AbstractLinkedList/AbstractLinkedNode";
|
|
2
|
-
|
|
3
|
-
export default class DoubleLinkedNode<T> extends AbstractLinkedNode<T> {
|
|
4
|
-
protected _prev: DoubleLinkedNode<T> | null;
|
|
5
|
-
protected _next: DoubleLinkedNode<T> | null;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Will create empty node
|
|
9
|
-
*/
|
|
10
|
-
public constructor(
|
|
11
|
-
data: T,
|
|
12
|
-
next: DoubleLinkedNode<T> | null = null,
|
|
13
|
-
prev: DoubleLinkedNode<T> | null = null
|
|
14
|
-
) {
|
|
15
|
-
super(data);
|
|
16
|
-
this._prev = prev;
|
|
17
|
-
this._next = next;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Set previous node link
|
|
22
|
-
*/
|
|
23
|
-
public set prev(value: DoubleLinkedNode<T> | null) {
|
|
24
|
-
this._prev = value;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Get previous node link
|
|
29
|
-
*/
|
|
30
|
-
public get prev(): DoubleLinkedNode<T> | null {
|
|
31
|
-
return this._prev;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @inheritDoc
|
|
36
|
-
*/
|
|
37
|
-
public set next(value: DoubleLinkedNode<T> | null) {
|
|
38
|
-
this._next = value;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @inheritDoc
|
|
43
|
-
*/
|
|
44
|
-
public get next(): DoubleLinkedNode<T> | null {
|
|
45
|
-
return this._next;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import IIterator from "../../../types/IIterator";
|
|
2
|
-
import IIterable from "../../../types/IIterable";
|
|
3
|
-
import AbstractLinkedList from "../AbstractLinkedList/AbstractLinkedList";
|
|
4
|
-
import SingleLinkedNode from "./SingleLinkedNode";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Linear data structure
|
|
8
|
-
* Each node has next
|
|
9
|
-
* Head's next node is tail
|
|
10
|
-
*/
|
|
11
|
-
export default class SingleLinkedList<T>
|
|
12
|
-
extends AbstractLinkedList<T>
|
|
13
|
-
implements IIterable<T> {
|
|
14
|
-
/**
|
|
15
|
-
* Override types
|
|
16
|
-
*/
|
|
17
|
-
protected _head: SingleLinkedNode<T> | null;
|
|
18
|
-
protected _tail: SingleLinkedNode<T> | null;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @inheritDoc
|
|
22
|
-
*/
|
|
23
|
-
public constructor(capacity?: number) {
|
|
24
|
-
super(capacity);
|
|
25
|
-
this._head = null;
|
|
26
|
-
this._tail = null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Find previous sibling of given node
|
|
31
|
-
*/
|
|
32
|
-
private getPrevNode(
|
|
33
|
-
node: SingleLinkedNode<T> | null
|
|
34
|
-
): SingleLinkedNode<T> | null {
|
|
35
|
-
let currentNode = this._tail;
|
|
36
|
-
while (currentNode?.next !== node) {
|
|
37
|
-
currentNode = currentNode?.next || null;
|
|
38
|
-
}
|
|
39
|
-
return currentNode;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @inheritDoc
|
|
44
|
-
*/
|
|
45
|
-
protected createNode(value: T): SingleLinkedNode<T> {
|
|
46
|
-
return new SingleLinkedNode<T>(value);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @inheritDoc
|
|
51
|
-
*/
|
|
52
|
-
protected insertNodeBetweenTwoNodesImpl(
|
|
53
|
-
targetNode: SingleLinkedNode<T>,
|
|
54
|
-
leftNode: SingleLinkedNode<T>,
|
|
55
|
-
rightNode: SingleLinkedNode<T>
|
|
56
|
-
): void {
|
|
57
|
-
targetNode.next = rightNode;
|
|
58
|
-
|
|
59
|
-
if (leftNode) {
|
|
60
|
-
leftNode.next = targetNode;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* @inheritDoc
|
|
66
|
-
*/
|
|
67
|
-
protected deleteNodeImpl(node: SingleLinkedNode<T>): void {
|
|
68
|
-
this.getPrevNode(node)!.next = node.next;
|
|
69
|
-
node.next = null;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* @inheritDoc
|
|
74
|
-
*/
|
|
75
|
-
protected popImpl(): void {
|
|
76
|
-
this._head = this.getPrevNode(this._tail);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* @inheritDoc
|
|
81
|
-
*/
|
|
82
|
-
protected shiftImpl(): void {
|
|
83
|
-
this._tail = this._head?.next || null;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* @inheritDoc
|
|
88
|
-
*/
|
|
89
|
-
public reverse(): void {
|
|
90
|
-
let currentNode: SingleLinkedNode<T> | null = this._tail;
|
|
91
|
-
let prevNode: SingleLinkedNode<T> | null = this._head;
|
|
92
|
-
let index = 0;
|
|
93
|
-
|
|
94
|
-
while (index < this._length) {
|
|
95
|
-
const next = currentNode?.next || null;
|
|
96
|
-
|
|
97
|
-
if (currentNode) {
|
|
98
|
-
currentNode.next = prevNode;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
index++;
|
|
102
|
-
prevNode = currentNode;
|
|
103
|
-
currentNode = next;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (currentNode) {
|
|
107
|
-
this._head = currentNode;
|
|
108
|
-
this._tail = currentNode.next;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* List iterator
|
|
114
|
-
*/
|
|
115
|
-
public iterator(fromIndex = 0): IIterator<T> {
|
|
116
|
-
const head = this._head;
|
|
117
|
-
let activeNode: SingleLinkedNode<T> = this.getNodeByIndex(fromIndex);
|
|
118
|
-
|
|
119
|
-
const iterator: IIterator<T> = {
|
|
120
|
-
/**
|
|
121
|
-
* @inheritDoc
|
|
122
|
-
*/
|
|
123
|
-
current: () => {
|
|
124
|
-
return activeNode.data;
|
|
125
|
-
},
|
|
126
|
-
/**
|
|
127
|
-
* @inheritDoc
|
|
128
|
-
*/
|
|
129
|
-
hasNext(): boolean {
|
|
130
|
-
return Boolean(activeNode.next) && activeNode !== head;
|
|
131
|
-
},
|
|
132
|
-
/**
|
|
133
|
-
* @inheritDoc
|
|
134
|
-
* @throws when next element does not exist
|
|
135
|
-
*/
|
|
136
|
-
next: (): T => {
|
|
137
|
-
if (!iterator.hasNext()) {
|
|
138
|
-
throw new Error("Next element does not exist");
|
|
139
|
-
}
|
|
140
|
-
activeNode = activeNode.next!;
|
|
141
|
-
return activeNode.data;
|
|
142
|
-
},
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
return iterator;
|
|
146
|
-
}
|
|
147
|
-
}
|