@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
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
extendStatics(d, b);
|
|
11
|
+
function __() { this.constructor = d; }
|
|
12
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
var AbstractLinkedNode_1 = require("../AbstractLinkedList/AbstractLinkedNode");
|
|
17
|
+
var DoubleLinkedNode = /** @class */ (function (_super) {
|
|
18
|
+
__extends(DoubleLinkedNode, _super);
|
|
19
|
+
/**
|
|
20
|
+
* Will create empty node
|
|
21
|
+
*/
|
|
22
|
+
function DoubleLinkedNode(data, next, prev) {
|
|
23
|
+
if (next === void 0) { next = null; }
|
|
24
|
+
if (prev === void 0) { prev = null; }
|
|
25
|
+
var _this = _super.call(this, data) || this;
|
|
26
|
+
_this._prev = prev;
|
|
27
|
+
_this._next = next;
|
|
28
|
+
return _this;
|
|
29
|
+
}
|
|
30
|
+
Object.defineProperty(DoubleLinkedNode.prototype, "prev", {
|
|
31
|
+
/**
|
|
32
|
+
* Get previous node link
|
|
33
|
+
*/
|
|
34
|
+
get: function () {
|
|
35
|
+
return this._prev;
|
|
36
|
+
},
|
|
37
|
+
/**
|
|
38
|
+
* Set previous node link
|
|
39
|
+
*/
|
|
40
|
+
set: function (value) {
|
|
41
|
+
this._prev = value;
|
|
42
|
+
},
|
|
43
|
+
enumerable: false,
|
|
44
|
+
configurable: true
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(DoubleLinkedNode.prototype, "next", {
|
|
47
|
+
/**
|
|
48
|
+
* @inheritDoc
|
|
49
|
+
*/
|
|
50
|
+
get: function () {
|
|
51
|
+
return this._next;
|
|
52
|
+
},
|
|
53
|
+
/**
|
|
54
|
+
* @inheritDoc
|
|
55
|
+
*/
|
|
56
|
+
set: function (value) {
|
|
57
|
+
this._next = value;
|
|
58
|
+
},
|
|
59
|
+
enumerable: false,
|
|
60
|
+
configurable: true
|
|
61
|
+
});
|
|
62
|
+
return DoubleLinkedNode;
|
|
63
|
+
}(AbstractLinkedNode_1.default));
|
|
64
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UFBO0lBUUgsdUJBQUM7QUFBRCxDQUFDLEFBNUNELENBQWlELDRCQUFrQixHQTRDbEUifQ==
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
* Linear data structure
|
|
7
|
+
* Each node has next
|
|
8
|
+
* Head's next node is tail
|
|
9
|
+
*/
|
|
10
|
+
export default class SingleLinkedList<T> extends AbstractLinkedList<T> implements IIterable<T> {
|
|
11
|
+
/**
|
|
12
|
+
* Override types
|
|
13
|
+
*/
|
|
14
|
+
protected _head: SingleLinkedNode<T> | null;
|
|
15
|
+
protected _tail: SingleLinkedNode<T> | null;
|
|
16
|
+
/**
|
|
17
|
+
* @inheritDoc
|
|
18
|
+
*/
|
|
19
|
+
constructor(capacity?: number);
|
|
20
|
+
/**
|
|
21
|
+
* Find previous sibling of given node
|
|
22
|
+
*/
|
|
23
|
+
private getPrevNode;
|
|
24
|
+
/**
|
|
25
|
+
* @inheritDoc
|
|
26
|
+
*/
|
|
27
|
+
protected createNode(value: T): SingleLinkedNode<T>;
|
|
28
|
+
/**
|
|
29
|
+
* @inheritDoc
|
|
30
|
+
*/
|
|
31
|
+
protected insertNodeBetweenTwoNodesImpl(targetNode: SingleLinkedNode<T>, leftNode: SingleLinkedNode<T>, rightNode: SingleLinkedNode<T>): void;
|
|
32
|
+
/**
|
|
33
|
+
* @inheritDoc
|
|
34
|
+
*/
|
|
35
|
+
protected deleteNodeImpl(node: SingleLinkedNode<T>): void;
|
|
36
|
+
/**
|
|
37
|
+
* @inheritDoc
|
|
38
|
+
*/
|
|
39
|
+
protected popImpl(): void;
|
|
40
|
+
/**
|
|
41
|
+
* @inheritDoc
|
|
42
|
+
*/
|
|
43
|
+
protected shiftImpl(): void;
|
|
44
|
+
/**
|
|
45
|
+
* @inheritDoc
|
|
46
|
+
*/
|
|
47
|
+
reverse(): void;
|
|
48
|
+
/**
|
|
49
|
+
* List iterator
|
|
50
|
+
*/
|
|
51
|
+
iterator(fromIndex?: number): IIterator<T>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
extendStatics(d, b);
|
|
11
|
+
function __() { this.constructor = d; }
|
|
12
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
var AbstractLinkedList_1 = require("../AbstractLinkedList/AbstractLinkedList");
|
|
17
|
+
var SingleLinkedNode_1 = require("./SingleLinkedNode");
|
|
18
|
+
/**
|
|
19
|
+
* Linear data structure
|
|
20
|
+
* Each node has next
|
|
21
|
+
* Head's next node is tail
|
|
22
|
+
*/
|
|
23
|
+
var SingleLinkedList = /** @class */ (function (_super) {
|
|
24
|
+
__extends(SingleLinkedList, _super);
|
|
25
|
+
/**
|
|
26
|
+
* @inheritDoc
|
|
27
|
+
*/
|
|
28
|
+
function SingleLinkedList(capacity) {
|
|
29
|
+
var _this = _super.call(this, capacity) || this;
|
|
30
|
+
_this._head = null;
|
|
31
|
+
_this._tail = null;
|
|
32
|
+
return _this;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Find previous sibling of given node
|
|
36
|
+
*/
|
|
37
|
+
SingleLinkedList.prototype.getPrevNode = function (node) {
|
|
38
|
+
var currentNode = this._tail;
|
|
39
|
+
while ((currentNode === null || currentNode === void 0 ? void 0 : currentNode.next) !== node) {
|
|
40
|
+
currentNode = (currentNode === null || currentNode === void 0 ? void 0 : currentNode.next) || null;
|
|
41
|
+
}
|
|
42
|
+
return currentNode;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* @inheritDoc
|
|
46
|
+
*/
|
|
47
|
+
SingleLinkedList.prototype.createNode = function (value) {
|
|
48
|
+
return new SingleLinkedNode_1.default(value);
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* @inheritDoc
|
|
52
|
+
*/
|
|
53
|
+
SingleLinkedList.prototype.insertNodeBetweenTwoNodesImpl = function (targetNode, leftNode, rightNode) {
|
|
54
|
+
targetNode.next = rightNode;
|
|
55
|
+
if (leftNode) {
|
|
56
|
+
leftNode.next = targetNode;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* @inheritDoc
|
|
61
|
+
*/
|
|
62
|
+
SingleLinkedList.prototype.deleteNodeImpl = function (node) {
|
|
63
|
+
this.getPrevNode(node).next = node.next;
|
|
64
|
+
node.next = null;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* @inheritDoc
|
|
68
|
+
*/
|
|
69
|
+
SingleLinkedList.prototype.popImpl = function () {
|
|
70
|
+
this._head = this.getPrevNode(this._tail);
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* @inheritDoc
|
|
74
|
+
*/
|
|
75
|
+
SingleLinkedList.prototype.shiftImpl = function () {
|
|
76
|
+
var _a;
|
|
77
|
+
this._tail = ((_a = this._head) === null || _a === void 0 ? void 0 : _a.next) || null;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* @inheritDoc
|
|
81
|
+
*/
|
|
82
|
+
SingleLinkedList.prototype.reverse = function () {
|
|
83
|
+
var currentNode = this._tail;
|
|
84
|
+
var prevNode = this._head;
|
|
85
|
+
var index = 0;
|
|
86
|
+
while (index < this._length) {
|
|
87
|
+
var next = (currentNode === null || currentNode === void 0 ? void 0 : currentNode.next) || null;
|
|
88
|
+
if (currentNode) {
|
|
89
|
+
currentNode.next = prevNode;
|
|
90
|
+
}
|
|
91
|
+
index++;
|
|
92
|
+
prevNode = currentNode;
|
|
93
|
+
currentNode = next;
|
|
94
|
+
}
|
|
95
|
+
if (currentNode) {
|
|
96
|
+
this._head = currentNode;
|
|
97
|
+
this._tail = currentNode.next;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* List iterator
|
|
102
|
+
*/
|
|
103
|
+
SingleLinkedList.prototype.iterator = function (fromIndex) {
|
|
104
|
+
if (fromIndex === void 0) { fromIndex = 0; }
|
|
105
|
+
var head = this._head;
|
|
106
|
+
var activeNode = this.getNodeByIndex(fromIndex);
|
|
107
|
+
var iterator = {
|
|
108
|
+
/**
|
|
109
|
+
* @inheritDoc
|
|
110
|
+
*/
|
|
111
|
+
current: function () {
|
|
112
|
+
return activeNode.data;
|
|
113
|
+
},
|
|
114
|
+
/**
|
|
115
|
+
* @inheritDoc
|
|
116
|
+
*/
|
|
117
|
+
hasNext: function () {
|
|
118
|
+
return Boolean(activeNode.next) && activeNode !== head;
|
|
119
|
+
},
|
|
120
|
+
/**
|
|
121
|
+
* @inheritDoc
|
|
122
|
+
* @throws when next element does not exist
|
|
123
|
+
*/
|
|
124
|
+
next: function () {
|
|
125
|
+
if (!iterator.hasNext()) {
|
|
126
|
+
throw new Error("Next element does not exist");
|
|
127
|
+
}
|
|
128
|
+
activeNode = activeNode.next;
|
|
129
|
+
return activeNode.data;
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
return iterator;
|
|
133
|
+
};
|
|
134
|
+
return SingleLinkedList;
|
|
135
|
+
}(AbstractLinkedList_1.default));
|
|
136
|
+
exports.default = SingleLinkedList;
|
|
137
|
+
//# sourceMapping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1lBQ3pCLENBQUM7U0FDRixDQUFDO1FBRUYsT0FBTyxRQUFRLENBQUM7SUFDbEIsQ0FBQztJQUNILHVCQUFDO0FBQUQsQ0FBQyxBQXhJRCxDQUNVLDRCQUFrQixHQXVJM0IifQ==
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import AbstractLinkedNode from "../AbstractLinkedList/AbstractLinkedNode";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
super(data, next);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
1
|
+
import AbstractLinkedNode from "../AbstractLinkedList/AbstractLinkedNode";
|
|
2
|
+
export default class SingleLinkedNode<T> extends AbstractLinkedNode<T> {
|
|
3
|
+
/**
|
|
4
|
+
* @inheritDoc
|
|
5
|
+
*/
|
|
6
|
+
constructor(data: T, next?: SingleLinkedNode<T> | null);
|
|
7
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
extendStatics(d, b);
|
|
11
|
+
function __() { this.constructor = d; }
|
|
12
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
var AbstractLinkedNode_1 = require("../AbstractLinkedList/AbstractLinkedNode");
|
|
17
|
+
var SingleLinkedNode = /** @class */ (function (_super) {
|
|
18
|
+
__extends(SingleLinkedNode, _super);
|
|
19
|
+
/**
|
|
20
|
+
* @inheritDoc
|
|
21
|
+
*/
|
|
22
|
+
function SingleLinkedNode(data, next) {
|
|
23
|
+
if (next === void 0) { next = null; }
|
|
24
|
+
return _super.call(this, data, next) || this;
|
|
25
|
+
}
|
|
26
|
+
return SingleLinkedNode;
|
|
27
|
+
}(AbstractLinkedNode_1.default));
|
|
28
|
+
exports.default = SingleLinkedNode;
|
|
29
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiU2luZ2xlTGlua2VkTm9kZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9kYXRhLXN0cnVjdHVyZXMvTGlua2VkTGlzdC9TaW5nbGVMaW5rZWRMaXN0L1NpbmdsZUxpbmtlZE5vZGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7O0FBQUEsK0VBQTBFO0FBRTFFO0lBQWlELG9DQUFxQjtJQUNwRTs7T0FFRztJQUNILDBCQUFtQixJQUFPLEVBQUUsSUFBdUM7UUFBdkMscUJBQUEsRUFBQSxXQUF1QztlQUNqRSxrQkFBTSxJQUFJLEVBQUUsSUFBSSxDQUFDO0lBQ25CLENBQUM7SUFDSCx1QkFBQztBQUFELENBQUMsQUFQRCxDQUFpRCw0QkFBa0IsR0FPbEUifQ==
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import IArrayFacade from "../../types/IArrayFacade";
|
|
2
|
+
/**
|
|
3
|
+
* Linear data structure
|
|
4
|
+
* Facade above array
|
|
5
|
+
* After reaching full array new pushed elements will be overwritten over old elements
|
|
6
|
+
*/
|
|
7
|
+
export default class LoopedArray<T> implements IArrayFacade<T> {
|
|
8
|
+
private readonly _capacity;
|
|
9
|
+
private _realLength;
|
|
10
|
+
private _array;
|
|
11
|
+
/**
|
|
12
|
+
* Create empty instance
|
|
13
|
+
*/
|
|
14
|
+
constructor(capacity: number);
|
|
15
|
+
/**
|
|
16
|
+
* Push into end
|
|
17
|
+
*/
|
|
18
|
+
push(value: T): void;
|
|
19
|
+
/**
|
|
20
|
+
* Push into start
|
|
21
|
+
*/
|
|
22
|
+
unshift(value: T): void;
|
|
23
|
+
/**
|
|
24
|
+
* Delete node from array's end
|
|
25
|
+
*/
|
|
26
|
+
pop(): T;
|
|
27
|
+
/**
|
|
28
|
+
* Delete node from array's start
|
|
29
|
+
*/
|
|
30
|
+
shift(): T;
|
|
31
|
+
/**
|
|
32
|
+
* Get head element data
|
|
33
|
+
* @throws Error when head does not exists
|
|
34
|
+
*/
|
|
35
|
+
peek(): T;
|
|
36
|
+
/**
|
|
37
|
+
* Get tail element data
|
|
38
|
+
* @throws Error when head does not exists
|
|
39
|
+
*/
|
|
40
|
+
peekFromStart(): T;
|
|
41
|
+
/**
|
|
42
|
+
* Get array element by index from start
|
|
43
|
+
* @throws when element does not exists
|
|
44
|
+
*/
|
|
45
|
+
peekByIndex(index: number): T;
|
|
46
|
+
/**
|
|
47
|
+
* Push from index
|
|
48
|
+
*/
|
|
49
|
+
pushFromIndex(value: T, fromIndex: number): void;
|
|
50
|
+
/**
|
|
51
|
+
* Get elements as array
|
|
52
|
+
*/
|
|
53
|
+
getAsArray(): Array<T>;
|
|
54
|
+
/**
|
|
55
|
+
* Check if element exists in array
|
|
56
|
+
*/
|
|
57
|
+
has(item: T): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Is array empty
|
|
60
|
+
*/
|
|
61
|
+
isEmpty(): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Is array full
|
|
64
|
+
*/
|
|
65
|
+
isFull(): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* List length
|
|
68
|
+
*/
|
|
69
|
+
length(): number;
|
|
70
|
+
/**
|
|
71
|
+
* Remove all elements from array
|
|
72
|
+
*/
|
|
73
|
+
clear(): void;
|
|
74
|
+
/**
|
|
75
|
+
* Delete node from array by index from start
|
|
76
|
+
*/
|
|
77
|
+
deleteFromIndex(fromIndex: number): T;
|
|
78
|
+
/**
|
|
79
|
+
* Add elements to array from array
|
|
80
|
+
* */
|
|
81
|
+
pushFromArray(elements: Array<T>): void;
|
|
82
|
+
/**
|
|
83
|
+
* Reverse array nodes links and swap head with tail
|
|
84
|
+
*/
|
|
85
|
+
reverse(): void;
|
|
86
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Linear data structure
|
|
5
|
+
* Facade above array
|
|
6
|
+
* After reaching full array new pushed elements will be overwritten over old elements
|
|
7
|
+
*/
|
|
8
|
+
var LoopedArray = /** @class */ (function () {
|
|
9
|
+
/**
|
|
10
|
+
* Create empty instance
|
|
11
|
+
*/
|
|
12
|
+
function LoopedArray(capacity) {
|
|
13
|
+
this._realLength = 0;
|
|
14
|
+
if (capacity <= 0) {
|
|
15
|
+
throw new Error("Capacity must be larger than 0");
|
|
16
|
+
}
|
|
17
|
+
this._capacity = capacity;
|
|
18
|
+
this._array = new Array(0);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Push into end
|
|
22
|
+
*/
|
|
23
|
+
LoopedArray.prototype.push = function (value) {
|
|
24
|
+
if (this._realLength % this._capacity === 0) {
|
|
25
|
+
this._array = new Array(0);
|
|
26
|
+
}
|
|
27
|
+
this._realLength++;
|
|
28
|
+
if (!this.isFull()) {
|
|
29
|
+
this._array.push(value);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
var indexToPush = (this._realLength % this._capacity) - 1;
|
|
33
|
+
this._array.splice(indexToPush, 1, value);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Push into start
|
|
38
|
+
*/
|
|
39
|
+
LoopedArray.prototype.unshift = function (value) {
|
|
40
|
+
if (this._realLength % this._capacity === 0) {
|
|
41
|
+
this._array = new Array(0);
|
|
42
|
+
}
|
|
43
|
+
this._realLength++;
|
|
44
|
+
if (!this.isFull()) {
|
|
45
|
+
this._array.unshift(value);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
this._array.splice(this._capacity - 1);
|
|
49
|
+
this._array.unshift(value);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Delete node from array's end
|
|
54
|
+
*/
|
|
55
|
+
LoopedArray.prototype.pop = function () {
|
|
56
|
+
this._realLength--;
|
|
57
|
+
var deletedItem = this._array.pop();
|
|
58
|
+
if (deletedItem === undefined)
|
|
59
|
+
throw new Error("cannot delete last element because of it does not exists");
|
|
60
|
+
return deletedItem;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Delete node from array's start
|
|
64
|
+
*/
|
|
65
|
+
LoopedArray.prototype.shift = function () {
|
|
66
|
+
this._realLength--;
|
|
67
|
+
var deletedItem = this._array.shift();
|
|
68
|
+
if (deletedItem === undefined)
|
|
69
|
+
throw new Error("cannot delete first element because of it does not exists");
|
|
70
|
+
return deletedItem;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Get head element data
|
|
74
|
+
* @throws Error when head does not exists
|
|
75
|
+
*/
|
|
76
|
+
LoopedArray.prototype.peek = function () {
|
|
77
|
+
return this._array[this._array.length - 1];
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Get tail element data
|
|
81
|
+
* @throws Error when head does not exists
|
|
82
|
+
*/
|
|
83
|
+
LoopedArray.prototype.peekFromStart = function () {
|
|
84
|
+
return this._array[0];
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Get array element by index from start
|
|
88
|
+
* @throws when element does not exists
|
|
89
|
+
*/
|
|
90
|
+
LoopedArray.prototype.peekByIndex = function (index) {
|
|
91
|
+
return this._array[index];
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Push from index
|
|
95
|
+
*/
|
|
96
|
+
LoopedArray.prototype.pushFromIndex = function (value, fromIndex) {
|
|
97
|
+
this._array[fromIndex] = value;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Get elements as array
|
|
101
|
+
*/
|
|
102
|
+
LoopedArray.prototype.getAsArray = function () {
|
|
103
|
+
return this._array;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Check if element exists in array
|
|
107
|
+
*/
|
|
108
|
+
LoopedArray.prototype.has = function (item) {
|
|
109
|
+
return this._array.includes(item);
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Is array empty
|
|
113
|
+
*/
|
|
114
|
+
LoopedArray.prototype.isEmpty = function () {
|
|
115
|
+
return this._array.length === 0;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Is array full
|
|
119
|
+
*/
|
|
120
|
+
LoopedArray.prototype.isFull = function () {
|
|
121
|
+
return this._array.length >= this._capacity;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* List length
|
|
125
|
+
*/
|
|
126
|
+
LoopedArray.prototype.length = function () {
|
|
127
|
+
return this._array.length;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Remove all elements from array
|
|
131
|
+
*/
|
|
132
|
+
LoopedArray.prototype.clear = function () {
|
|
133
|
+
this._array = new Array(0);
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Delete node from array by index from start
|
|
137
|
+
*/
|
|
138
|
+
LoopedArray.prototype.deleteFromIndex = function (fromIndex) {
|
|
139
|
+
var deletedElement = this._array[fromIndex];
|
|
140
|
+
delete this._array[fromIndex];
|
|
141
|
+
return deletedElement;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Add elements to array from array
|
|
145
|
+
* */
|
|
146
|
+
LoopedArray.prototype.pushFromArray = function (elements) {
|
|
147
|
+
var _this = this;
|
|
148
|
+
elements.forEach(function (element) {
|
|
149
|
+
_this.push(element);
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Reverse array nodes links and swap head with tail
|
|
154
|
+
*/
|
|
155
|
+
LoopedArray.prototype.reverse = function () {
|
|
156
|
+
this._array = this._array.reverse();
|
|
157
|
+
};
|
|
158
|
+
return LoopedArray;
|
|
159
|
+
}());
|
|
160
|
+
exports.default = LoopedArray;
|
|
161
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTG9vcGVkQXJyYXkuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvZGF0YS1zdHJ1Y3R1cmVzL0xvb3BlZEFycmF5L0xvb3BlZEFycmF5LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBRUE7Ozs7R0FJRztBQUNIO0lBS0U7O09BRUc7SUFDSCxxQkFBWSxRQUFnQjtRQU5wQixnQkFBVyxHQUFHLENBQUMsQ0FBQztRQU90QixJQUFJLFFBQVEsSUFBSSxDQUFDLEVBQUU7WUFDakIsTUFBTSxJQUFJLEtBQUssQ0FBQyxnQ0FBZ0MsQ0FBQyxDQUFDO1NBQ25EO1FBQ0QsSUFBSSxDQUFDLFNBQVMsR0FBRyxRQUFRLENBQUM7UUFDMUIsSUFBSSxDQUFDLE1BQU0sR0FBRyxJQUFJLEtBQUssQ0FBSSxDQUFDLENBQUMsQ0FBQztJQUNoQyxDQUFDO0lBRUQ7O09BRUc7SUFDSSwwQkFBSSxHQUFYLFVBQVksS0FBUTtRQUNsQixJQUFJLElBQUksQ0FBQyxXQUFXLEdBQUcsSUFBSSxDQUFDLFNBQVMsS0FBSyxDQUFDLEVBQUU7WUFDM0MsSUFBSSxDQUFDLE1BQU0sR0FBRyxJQUFJLEtBQUssQ0FBSSxDQUFDLENBQUMsQ0FBQztTQUMvQjtRQUVELElBQUksQ0FBQyxXQUFXLEVBQUUsQ0FBQztRQUVuQixJQUFJLENBQUMsSUFBSSxDQUFDLE1BQU0sRUFBR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UFFRDs7T0FFRztJQUNILDZCQUFPLEdBQVA7UUFDRSxJQUFJLENBQUMsTUFBTSxHQUFHLElBQUksQ0FBQyxNQUFNLENBQUMsT0FBTyxFQUFFLENBQUM7SUFDdEMsQ0FBQztJQUNILGtCQUFDO0FBQUQsQ0FBQyxBQTlLRCxJQThLQyJ9
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import ILinearStorage from "../../types/ILinearStorage";
|
|
2
|
+
/**
|
|
3
|
+
* FIFO data structure
|
|
4
|
+
*/
|
|
5
|
+
export default class Queue<T> implements ILinearStorage<T> {
|
|
6
|
+
private readonly _list;
|
|
7
|
+
/**
|
|
8
|
+
* Create a queue instance
|
|
9
|
+
*/
|
|
10
|
+
constructor(capacity?: number);
|
|
11
|
+
/**
|
|
12
|
+
* Get first element in queue (without deleting)
|
|
13
|
+
* @throws when list is empty
|
|
14
|
+
*/
|
|
15
|
+
peek(): T;
|
|
16
|
+
/**
|
|
17
|
+
* Add element to queue
|
|
18
|
+
* @throws when list is full
|
|
19
|
+
*/
|
|
20
|
+
push(item: T): void;
|
|
21
|
+
/**
|
|
22
|
+
* Delete first element in queue
|
|
23
|
+
* @throws when list is empty
|
|
24
|
+
*/
|
|
25
|
+
pop(): T;
|
|
26
|
+
/**
|
|
27
|
+
* Check if element exists in list
|
|
28
|
+
*/
|
|
29
|
+
has(item: T): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Is queue empty
|
|
32
|
+
*/
|
|
33
|
+
isEmpty(): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Is stack full
|
|
36
|
+
*/
|
|
37
|
+
isFull(): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Remove all elements in queue
|
|
40
|
+
*/
|
|
41
|
+
clear(): void;
|
|
42
|
+
/**
|
|
43
|
+
* Queue length
|
|
44
|
+
*/
|
|
45
|
+
length(): number;
|
|
46
|
+
/**
|
|
47
|
+
* Reverse queue
|
|
48
|
+
*/
|
|
49
|
+
reverse(): void;
|
|
50
|
+
}
|