@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,78 +0,0 @@
|
|
|
1
|
-
import DoubleLinkedList from "../data-structures/LinkedList/DoubleLinkedList/DoubleLinkedList";
|
|
2
|
-
import ILinkedList from "../types/ILinkedList";
|
|
3
|
-
|
|
4
|
-
export const demoLinkedList = (): void => {
|
|
5
|
-
console.log("\nEmpty linked list created");
|
|
6
|
-
const list: ILinkedList<string> = new DoubleLinkedList<string>();
|
|
7
|
-
|
|
8
|
-
list.push("John");
|
|
9
|
-
list.push("Mary");
|
|
10
|
-
console.log("\nJohn and Mary were added");
|
|
11
|
-
console.log(list.getAsArray());
|
|
12
|
-
|
|
13
|
-
list.push("Kate");
|
|
14
|
-
console.log("\nKate was added to end");
|
|
15
|
-
console.log(list.getAsArray());
|
|
16
|
-
|
|
17
|
-
console.log("\nChecking is list has John: ");
|
|
18
|
-
console.log(list.has("John"));
|
|
19
|
-
|
|
20
|
-
list.shift();
|
|
21
|
-
console.log("\nDeleting first element... ");
|
|
22
|
-
console.log("\nChecking is list has John: ");
|
|
23
|
-
console.log(list.has("John"));
|
|
24
|
-
console.log(list.getAsArray());
|
|
25
|
-
|
|
26
|
-
list.pop();
|
|
27
|
-
console.log("\nDeleting last element... ");
|
|
28
|
-
console.log("\nCheck is list has Kate: ");
|
|
29
|
-
console.log(list.has("Kate"));
|
|
30
|
-
console.log(list.getAsArray());
|
|
31
|
-
|
|
32
|
-
list.push("Bob");
|
|
33
|
-
list.push("Elon");
|
|
34
|
-
console.log("\nAdding Bob и Elon: ");
|
|
35
|
-
console.log(list.getAsArray());
|
|
36
|
-
|
|
37
|
-
list.unshift("Dan");
|
|
38
|
-
console.log("\nAdding Dan to start: ");
|
|
39
|
-
console.log(list.getAsArray());
|
|
40
|
-
|
|
41
|
-
list.deleteFromIndex(2);
|
|
42
|
-
console.log("\nDelete item by index 2: ");
|
|
43
|
-
console.log(list.getAsArray());
|
|
44
|
-
|
|
45
|
-
list.pushFromIndex("Sam", 2);
|
|
46
|
-
console.log("\nAdding Sam by index 2: ");
|
|
47
|
-
console.log(list.getAsArray());
|
|
48
|
-
|
|
49
|
-
console.log("\nCheck if head and tail correctly linked with each other");
|
|
50
|
-
console.log(list);
|
|
51
|
-
|
|
52
|
-
console.log("\nArray length is: ");
|
|
53
|
-
console.log(list.length());
|
|
54
|
-
|
|
55
|
-
console.log("\nPeek last element: ");
|
|
56
|
-
console.log(list.peek());
|
|
57
|
-
|
|
58
|
-
console.log("\nPeek first element: ");
|
|
59
|
-
console.log(list.peekFromStart());
|
|
60
|
-
|
|
61
|
-
console.log("\nPeek by index 2: ");
|
|
62
|
-
console.log(list.peekByIndex(2));
|
|
63
|
-
|
|
64
|
-
list.reverse();
|
|
65
|
-
console.log("\nReversing list... ");
|
|
66
|
-
console.log("\nReversed list: ");
|
|
67
|
-
console.log(list.getAsArray());
|
|
68
|
-
|
|
69
|
-
console.log("\nCheck if head and tail correctly linked with each other");
|
|
70
|
-
console.log(list);
|
|
71
|
-
|
|
72
|
-
list.clear();
|
|
73
|
-
console.log("\nClear list... ");
|
|
74
|
-
|
|
75
|
-
console.log("\nCheck is list empty:");
|
|
76
|
-
console.log(list.isEmpty());
|
|
77
|
-
console.log(list.getAsArray());
|
|
78
|
-
};
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import LoopedArray from "../data-structures/LoopedArray/LoopedArray";
|
|
2
|
-
import IArrayFacade from "../types/IArrayFacade";
|
|
3
|
-
|
|
4
|
-
export const demoLoopedArray = (): void => {
|
|
5
|
-
console.log("LoopedArray instance was created with capacity = 4");
|
|
6
|
-
const loopedArray: IArrayFacade<string> = new LoopedArray<string>(4);
|
|
7
|
-
|
|
8
|
-
loopedArray.push("John");
|
|
9
|
-
loopedArray.push("Mary");
|
|
10
|
-
console.log("\nJohn and Mary were added");
|
|
11
|
-
console.log(loopedArray.getAsArray());
|
|
12
|
-
|
|
13
|
-
loopedArray.push("Kate");
|
|
14
|
-
console.log("\nKate was added to end");
|
|
15
|
-
console.log(loopedArray.getAsArray());
|
|
16
|
-
|
|
17
|
-
console.log("\nChecking is array has John: ");
|
|
18
|
-
console.log(loopedArray.has("John"));
|
|
19
|
-
|
|
20
|
-
loopedArray.shift();
|
|
21
|
-
console.log("\nDeleting first element... ");
|
|
22
|
-
console.log("\nChecking is array has John: ");
|
|
23
|
-
console.log(loopedArray.has("John"));
|
|
24
|
-
console.log(loopedArray.getAsArray());
|
|
25
|
-
|
|
26
|
-
loopedArray.pop();
|
|
27
|
-
console.log("\nDeleting last element... ");
|
|
28
|
-
console.log("\nCheck is array has Kate: ");
|
|
29
|
-
console.log(loopedArray.has("Kate"));
|
|
30
|
-
console.log(loopedArray.getAsArray());
|
|
31
|
-
|
|
32
|
-
loopedArray.push("Bob");
|
|
33
|
-
loopedArray.push("Elon");
|
|
34
|
-
console.log("\nAdding Bob и Elon: ");
|
|
35
|
-
console.log(loopedArray.getAsArray());
|
|
36
|
-
|
|
37
|
-
loopedArray.unshift("Dan");
|
|
38
|
-
console.log("\nAdding Dan to start: ");
|
|
39
|
-
console.log(loopedArray.getAsArray());
|
|
40
|
-
|
|
41
|
-
loopedArray.deleteFromIndex(2);
|
|
42
|
-
console.log("\nDelete item by index 2: ");
|
|
43
|
-
console.log(loopedArray.getAsArray());
|
|
44
|
-
|
|
45
|
-
loopedArray.pushFromIndex("Sam", 2);
|
|
46
|
-
console.log("\nAdding Sam by index 2: ");
|
|
47
|
-
console.log(loopedArray.getAsArray());
|
|
48
|
-
|
|
49
|
-
console.log("\nArray length is: ");
|
|
50
|
-
console.log(loopedArray.length());
|
|
51
|
-
|
|
52
|
-
console.log("\nPeek last element: ");
|
|
53
|
-
console.log(loopedArray.peek());
|
|
54
|
-
|
|
55
|
-
console.log("\nPeek first element: ");
|
|
56
|
-
console.log(loopedArray.peekFromStart());
|
|
57
|
-
|
|
58
|
-
console.log("\nPeek by index 2: ");
|
|
59
|
-
console.log(loopedArray.peekByIndex(2));
|
|
60
|
-
|
|
61
|
-
loopedArray.reverse();
|
|
62
|
-
console.log("\nReversing array... ");
|
|
63
|
-
console.log("\nReversed array: ");
|
|
64
|
-
console.log(loopedArray.getAsArray());
|
|
65
|
-
|
|
66
|
-
loopedArray.push("OW_END_1");
|
|
67
|
-
console.log("\nAdding to end when array is full");
|
|
68
|
-
console.log(loopedArray.getAsArray());
|
|
69
|
-
|
|
70
|
-
loopedArray.push("OW_END_2");
|
|
71
|
-
console.log("\nAdding to end when array is full");
|
|
72
|
-
console.log(loopedArray.getAsArray());
|
|
73
|
-
|
|
74
|
-
loopedArray.push("OW_END_3");
|
|
75
|
-
console.log("\nAdding to end when array is full");
|
|
76
|
-
console.log(loopedArray.getAsArray());
|
|
77
|
-
|
|
78
|
-
loopedArray.push("OW_END_4");
|
|
79
|
-
console.log("\nAdding to end when array is full");
|
|
80
|
-
console.log(loopedArray.getAsArray());
|
|
81
|
-
|
|
82
|
-
loopedArray.unshift("OW_START_1");
|
|
83
|
-
console.log("\nAdding to start when array is full");
|
|
84
|
-
console.log(loopedArray.getAsArray());
|
|
85
|
-
|
|
86
|
-
loopedArray.unshift("OW_START_2");
|
|
87
|
-
console.log("\nAdding to start when array is full");
|
|
88
|
-
console.log(loopedArray.getAsArray());
|
|
89
|
-
|
|
90
|
-
loopedArray.unshift("OW_START_3");
|
|
91
|
-
console.log("\nAdding to start when array is full");
|
|
92
|
-
console.log(loopedArray.getAsArray());
|
|
93
|
-
|
|
94
|
-
loopedArray.unshift("OW_START_4");
|
|
95
|
-
console.log("\nAdding to start when array is full");
|
|
96
|
-
console.log(loopedArray.getAsArray());
|
|
97
|
-
|
|
98
|
-
loopedArray.clear();
|
|
99
|
-
console.log("\nClear array... ");
|
|
100
|
-
|
|
101
|
-
console.log("\nCheck is array empty:");
|
|
102
|
-
console.log(loopedArray.isEmpty());
|
|
103
|
-
console.log(loopedArray.getAsArray());
|
|
104
|
-
};
|
package/src/demo/demo.queue.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import Queue from "../data-structures/Queue/Queue";
|
|
2
|
-
import ILinearStorage from "../types/ILinearStorage";
|
|
3
|
-
|
|
4
|
-
export const demoQueue = (): void => {
|
|
5
|
-
console.log("\nEmpty queue created");
|
|
6
|
-
const queue: ILinearStorage<string> = new Queue<string>();
|
|
7
|
-
|
|
8
|
-
queue.push("John");
|
|
9
|
-
queue.push("Mary");
|
|
10
|
-
console.log("\nJohn and Mary were added");
|
|
11
|
-
console.log("\n*John > Mary*");
|
|
12
|
-
console.log("\nQueue peek element:");
|
|
13
|
-
console.log(queue.peek());
|
|
14
|
-
|
|
15
|
-
queue.push("Kate");
|
|
16
|
-
console.log("\nKate was added to end");
|
|
17
|
-
console.log("\n*John > Mary > Kate*");
|
|
18
|
-
console.log("\nQueue peek element:");
|
|
19
|
-
console.log(queue.peek());
|
|
20
|
-
|
|
21
|
-
console.log("\nChecking is queue has John: ");
|
|
22
|
-
console.log(queue.has("John"));
|
|
23
|
-
|
|
24
|
-
queue.pop();
|
|
25
|
-
console.log("\nPop element... ");
|
|
26
|
-
console.log("\nCheck is queue has John: ");
|
|
27
|
-
console.log(queue.has("John"));
|
|
28
|
-
console.log("\n*Mary > Kate*");
|
|
29
|
-
console.log("\nQueue peek element:");
|
|
30
|
-
console.log(queue.peek());
|
|
31
|
-
|
|
32
|
-
console.log("\nArray length is: ");
|
|
33
|
-
console.log(queue.length());
|
|
34
|
-
|
|
35
|
-
queue.clear();
|
|
36
|
-
console.log("\nClear queue... ");
|
|
37
|
-
|
|
38
|
-
console.log("\nCheck is queue empty:");
|
|
39
|
-
console.log(queue.isEmpty());
|
|
40
|
-
};
|
package/src/demo/demo.stack.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import ILinearStorage from "../types/ILinearStorage";
|
|
2
|
-
import Stack from "../data-structures/Stack/Stack";
|
|
3
|
-
|
|
4
|
-
export const demoStack = (): void => {
|
|
5
|
-
console.log("\nEmpty stack created");
|
|
6
|
-
const stack: ILinearStorage<string> = new Stack<string>();
|
|
7
|
-
|
|
8
|
-
stack.push("John");
|
|
9
|
-
stack.push("Mary");
|
|
10
|
-
console.log("\nJohn and Mary were added");
|
|
11
|
-
console.log("\n*John > Mary*");
|
|
12
|
-
console.log("\nStack peek element:");
|
|
13
|
-
console.log(stack.peek());
|
|
14
|
-
|
|
15
|
-
stack.push("Kate");
|
|
16
|
-
console.log("\nKate was added to end");
|
|
17
|
-
console.log("\n*John > Mary > Kate*");
|
|
18
|
-
console.log("\nStack peek element:");
|
|
19
|
-
console.log(stack.peek());
|
|
20
|
-
|
|
21
|
-
console.log("\nChecking is stack has John: ");
|
|
22
|
-
console.log(stack.has("John"));
|
|
23
|
-
|
|
24
|
-
stack.pop();
|
|
25
|
-
console.log("\nPop element... ");
|
|
26
|
-
console.log("\nCheck is stack has Kate: ");
|
|
27
|
-
console.log(stack.has("Kate"));
|
|
28
|
-
console.log("\n*John > Mary*");
|
|
29
|
-
console.log("\nStack peek element:");
|
|
30
|
-
console.log(stack.peek());
|
|
31
|
-
|
|
32
|
-
console.log("\nArray length is: ");
|
|
33
|
-
console.log(stack.length());
|
|
34
|
-
|
|
35
|
-
stack.clear();
|
|
36
|
-
console.log("\nClear stack... ");
|
|
37
|
-
|
|
38
|
-
console.log("\nCheck is stack empty:");
|
|
39
|
-
console.log(stack.isEmpty());
|
|
40
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import RandBinarySearchTree from "../../data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchTree";
|
|
2
|
-
import BinarySearchTree from "../../data-structures/BinaryTree/BinarySearchTree/BinarySearchTree";
|
|
3
|
-
import IBinaryTree from "../../types/IBinaryTree";
|
|
4
|
-
|
|
5
|
-
const logTree = <T>(tree: IBinaryTree<T>) => {
|
|
6
|
-
console.log("HEIGHT");
|
|
7
|
-
console.log(tree.height());
|
|
8
|
-
console.log("LENGTH");
|
|
9
|
-
console.log(tree.length());
|
|
10
|
-
console.log("MAX");
|
|
11
|
-
console.log(tree.max());
|
|
12
|
-
console.log("MIN");
|
|
13
|
-
console.log(tree.min());
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const bstCompare = (): void => {
|
|
17
|
-
const bstLeaf = new BinarySearchTree<number>();
|
|
18
|
-
const bstRand = new RandBinarySearchTree<number>();
|
|
19
|
-
|
|
20
|
-
const arraySrc = Array.from(Array(1000).keys());
|
|
21
|
-
|
|
22
|
-
arraySrc.forEach((num) => {
|
|
23
|
-
bstLeaf.insert(num);
|
|
24
|
-
bstRand.insert(num);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
console.log(
|
|
28
|
-
"***************************LEAF TREE*****************************"
|
|
29
|
-
);
|
|
30
|
-
logTree<number>(bstLeaf);
|
|
31
|
-
console.log(
|
|
32
|
-
"\n\n\n***************************RAND TREE*****************************"
|
|
33
|
-
);
|
|
34
|
-
logTree<number>(bstRand);
|
|
35
|
-
};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import Queue from "../../data-structures/Queue/Queue";
|
|
2
|
-
import Stack from "../../data-structures/Stack/Stack";
|
|
3
|
-
import ILinearStorage from "../../types/ILinearStorage";
|
|
4
|
-
import { perf, roundNumber } from "../../utils";
|
|
5
|
-
|
|
6
|
-
export const pushToLinearDS = (
|
|
7
|
-
linearDS: ILinearStorage<string>,
|
|
8
|
-
elementsCount: number,
|
|
9
|
-
item: string
|
|
10
|
-
): void => {
|
|
11
|
-
for (let i = 0; i < elementsCount; i++) {
|
|
12
|
-
linearDS.push(`${item}_${i}`);
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const perfLinearDS = (linearDS: ILinearStorage<string>): void => {
|
|
17
|
-
let elementsCount = 50;
|
|
18
|
-
|
|
19
|
-
while (elementsCount <= 5000000) {
|
|
20
|
-
pushToLinearDS(linearDS, elementsCount, "qwerty");
|
|
21
|
-
|
|
22
|
-
const perfPush = perf(() => {
|
|
23
|
-
linearDS.push("qwerty");
|
|
24
|
-
});
|
|
25
|
-
const perfPeek = perf(() => {
|
|
26
|
-
linearDS.peek();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const perfPop = perf(() => {
|
|
30
|
-
linearDS.pop();
|
|
31
|
-
});
|
|
32
|
-
const perfHas = perf(() => {
|
|
33
|
-
linearDS.has(`qwerty_${elementsCount - 10}`);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
console.log(`N: ${elementsCount} push: ${roundNumber(perfPush)}ms`);
|
|
37
|
-
console.log(`N: ${elementsCount} peek: ${roundNumber(perfPeek)}ms`);
|
|
38
|
-
console.log(`N: ${elementsCount} pop: ${roundNumber(perfPop)}ms`);
|
|
39
|
-
console.log(`N: ${elementsCount} has: ${roundNumber(perfHas)}ms`);
|
|
40
|
-
console.log("=========================");
|
|
41
|
-
|
|
42
|
-
elementsCount *= 10;
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export const perfQueue = (): void => {
|
|
47
|
-
console.log(`QUEUE PERFORMANCE TEST:`);
|
|
48
|
-
const queue: ILinearStorage<string> = new Queue<string>();
|
|
49
|
-
|
|
50
|
-
perfLinearDS(queue);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export const perfStack = (): void => {
|
|
54
|
-
console.log(`STACK PERFORMANCE TEST:`);
|
|
55
|
-
const stack: ILinearStorage<string> = new Stack<string>();
|
|
56
|
-
|
|
57
|
-
perfLinearDS(stack);
|
|
58
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { perf, roundNumber } from "../../utils";
|
|
2
|
-
import IKeyValueStorage from "../../types/IKeyValueStorage";
|
|
3
|
-
import HashTable from "../../data-structures/HashTable/HashTable";
|
|
4
|
-
|
|
5
|
-
export const pushToStorage = (
|
|
6
|
-
linearDS: IKeyValueStorage<number>,
|
|
7
|
-
elementsCount: number
|
|
8
|
-
): void => {
|
|
9
|
-
for (let i = 0; i < elementsCount; i++) {
|
|
10
|
-
linearDS.set(`key${i}`, i);
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const perfHashTable = (): void => {
|
|
15
|
-
console.log(`HASHTABLE PERFORMANCE TEST:`);
|
|
16
|
-
const hashTable: IKeyValueStorage<number> = new HashTable<number>();
|
|
17
|
-
let elementsCount = 50;
|
|
18
|
-
|
|
19
|
-
while (elementsCount <= 5000000) {
|
|
20
|
-
pushToStorage(hashTable, elementsCount);
|
|
21
|
-
|
|
22
|
-
const perfSet = perf(() => {
|
|
23
|
-
hashTable.set(`key${elementsCount}`, elementsCount);
|
|
24
|
-
});
|
|
25
|
-
const perfGet = perf(() => {
|
|
26
|
-
hashTable.get(`key${elementsCount}`);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const perfHas = perf(() => {
|
|
30
|
-
hashTable.has(`key${elementsCount - 10}`);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
console.log(`N: ${elementsCount} set: ${roundNumber(perfSet)}ms`);
|
|
34
|
-
console.log(`N: ${elementsCount} get: ${roundNumber(perfGet)}ms`);
|
|
35
|
-
console.log(`N: ${elementsCount} has: ${roundNumber(perfHas)}ms`);
|
|
36
|
-
console.log("=========================");
|
|
37
|
-
|
|
38
|
-
elementsCount *= 10;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { FnSort } from "../../types/FnSort";
|
|
2
|
-
import { mergeSort } from "../../algorithms/sorts/merge-sort";
|
|
3
|
-
import { insertionSort } from "../../algorithms/sorts/insertion-sort";
|
|
4
|
-
import { bubbleSort } from "../../algorithms/sorts/bubble-sort";
|
|
5
|
-
import { quickSort } from "../../algorithms/sorts/quick-sort";
|
|
6
|
-
import { selectSort } from "../../algorithms/sorts/select-sort";
|
|
7
|
-
import { perf } from "../../utils";
|
|
8
|
-
|
|
9
|
-
export const randomizeArray = (length: number, max: number): Array<number> =>
|
|
10
|
-
new Array(length).fill(0).map(() => Math.round(Math.random() * max));
|
|
11
|
-
|
|
12
|
-
export const sortCompare = (
|
|
13
|
-
sortFn: FnSort,
|
|
14
|
-
n: number,
|
|
15
|
-
callsNumber: number
|
|
16
|
-
): void => {
|
|
17
|
-
let totalTime = 0;
|
|
18
|
-
|
|
19
|
-
for (let i = 0; i < callsNumber; i++) {
|
|
20
|
-
const generatedArr = randomizeArray(n, 1000);
|
|
21
|
-
const perfResult = perf(() => {
|
|
22
|
-
sortFn(generatedArr);
|
|
23
|
-
});
|
|
24
|
-
totalTime += perfResult;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const averageTime = totalTime / callsNumber;
|
|
28
|
-
|
|
29
|
-
console.log(`N: ${n} = ${averageTime}ms`);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const sortCompareRunner = (
|
|
33
|
-
sortFn: FnSort,
|
|
34
|
-
callsNumber: number
|
|
35
|
-
): void => {
|
|
36
|
-
sortCompare(sortFn, 5, callsNumber);
|
|
37
|
-
sortCompare(sortFn, 50, callsNumber);
|
|
38
|
-
sortCompare(sortFn, 500, callsNumber);
|
|
39
|
-
sortCompare(sortFn, 5000, callsNumber);
|
|
40
|
-
sortCompare(sortFn, 50000, callsNumber);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export const compareAllSortTypes = (): void => {
|
|
44
|
-
const callsNumber = 10;
|
|
45
|
-
|
|
46
|
-
console.log(`MERGE SORT:`);
|
|
47
|
-
sortCompareRunner(mergeSort, callsNumber);
|
|
48
|
-
|
|
49
|
-
console.log(`QUICK SORT:`);
|
|
50
|
-
sortCompareRunner(quickSort, callsNumber);
|
|
51
|
-
|
|
52
|
-
console.log(`SELECTION SORT:`);
|
|
53
|
-
sortCompareRunner(selectSort, callsNumber);
|
|
54
|
-
|
|
55
|
-
console.log(`BUBBLE SORT:`);
|
|
56
|
-
sortCompareRunner(bubbleSort, callsNumber);
|
|
57
|
-
|
|
58
|
-
console.log(`INSERTION SORT:`);
|
|
59
|
-
sortCompareRunner(insertionSort, callsNumber);
|
|
60
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { EnumBinarySearchTreeType } from "../types/EnumBinarySearchTreeType";
|
|
2
|
-
import BinarySearchTree from "../data-structures/BinaryTree/BinarySearchTree/BinarySearchTree";
|
|
3
|
-
import RandBinarySearchTree from "../data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchTree";
|
|
4
|
-
import IBinaryTree from "../types/IBinaryTree";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Returns binary tree by type
|
|
8
|
-
*/
|
|
9
|
-
export const createBinaryTree = <T>(
|
|
10
|
-
type: EnumBinarySearchTreeType
|
|
11
|
-
): IBinaryTree<T> => {
|
|
12
|
-
let binaryTree: IBinaryTree<T>;
|
|
13
|
-
|
|
14
|
-
switch (type) {
|
|
15
|
-
case EnumBinarySearchTreeType.BST:
|
|
16
|
-
binaryTree = new BinarySearchTree();
|
|
17
|
-
break;
|
|
18
|
-
case EnumBinarySearchTreeType.RANDOMIZED_BST:
|
|
19
|
-
binaryTree = new RandBinarySearchTree();
|
|
20
|
-
break;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return binaryTree;
|
|
24
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import IGraph from "../types/IGraph";
|
|
2
|
-
import DirectedGraph from "../data-structures/Graph/DirectedGraph";
|
|
3
|
-
import UndirectedGraph from "../data-structures/Graph/UndirectedGraph";
|
|
4
|
-
import { EnumGraphType } from "../types/EnumGraphType";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Returns graph by type
|
|
8
|
-
*/
|
|
9
|
-
export const createGraph = <T>(type: EnumGraphType): IGraph<T> => {
|
|
10
|
-
let graph: IGraph<T>;
|
|
11
|
-
|
|
12
|
-
switch (type) {
|
|
13
|
-
case EnumGraphType.Directed:
|
|
14
|
-
graph = new DirectedGraph();
|
|
15
|
-
break;
|
|
16
|
-
case EnumGraphType.Undirected:
|
|
17
|
-
graph = new UndirectedGraph();
|
|
18
|
-
break;
|
|
19
|
-
default:
|
|
20
|
-
throw new Error("Invalid graph type");
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return graph;
|
|
24
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import IGraph from "../types/IGraph";
|
|
2
|
-
import { EnumGraphType } from "../types/EnumGraphType";
|
|
3
|
-
import { ArrayMatrix } from "../types/ArrayMatrix";
|
|
4
|
-
import { createGraph } from "./createGraph";
|
|
5
|
-
import { EDGE_EXISTS_STATE } from "../constants";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Creates a graph from N*N matrix that contains 1 in case of edge exists or 0 in case it does not
|
|
9
|
-
*/
|
|
10
|
-
export const createGraphFromMatrix = <T>(
|
|
11
|
-
matrix: ArrayMatrix,
|
|
12
|
-
fieldsList: Array<T>,
|
|
13
|
-
type: EnumGraphType
|
|
14
|
-
): IGraph<T> => {
|
|
15
|
-
const graph: IGraph<T> = createGraph(type);
|
|
16
|
-
|
|
17
|
-
fieldsList.forEach((fieldName) => {
|
|
18
|
-
graph.addVertex(fieldName);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
matrix.forEach((row: Array<number>, rowIndex: number) => {
|
|
22
|
-
row.forEach((col: number, colIndex: number) => {
|
|
23
|
-
const rowColState = matrix[rowIndex][colIndex];
|
|
24
|
-
const colRowState = matrix[colIndex][rowIndex];
|
|
25
|
-
|
|
26
|
-
if (type === EnumGraphType.Undirected) {
|
|
27
|
-
if (
|
|
28
|
-
rowColState === EDGE_EXISTS_STATE &&
|
|
29
|
-
colRowState === EDGE_EXISTS_STATE
|
|
30
|
-
) {
|
|
31
|
-
graph.addEdge(fieldsList[rowIndex], fieldsList[colIndex]);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (type === EnumGraphType.Directed) {
|
|
36
|
-
if (rowColState === EDGE_EXISTS_STATE) {
|
|
37
|
-
graph.addEdge(fieldsList[rowIndex], fieldsList[colIndex]);
|
|
38
|
-
}
|
|
39
|
-
if (colRowState === EDGE_EXISTS_STATE) {
|
|
40
|
-
graph.addEdge(fieldsList[colIndex], fieldsList[rowIndex]);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
return graph;
|
|
47
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { EnumLinkedListType } from "../types/EnumLinkedListType";
|
|
2
|
-
import DoubleLinkedList from "../data-structures/LinkedList/DoubleLinkedList/DoubleLinkedList";
|
|
3
|
-
import SingleLinkedList from "../data-structures/LinkedList/SingleLinkedList/SingleLinkedList";
|
|
4
|
-
import ILinkedList from "../types/ILinkedList";
|
|
5
|
-
|
|
6
|
-
export const createLinkedList = <T>(
|
|
7
|
-
type: EnumLinkedListType,
|
|
8
|
-
capacity?: number
|
|
9
|
-
): ILinkedList<T> => {
|
|
10
|
-
let linkedList: ILinkedList<T>;
|
|
11
|
-
|
|
12
|
-
switch (type) {
|
|
13
|
-
case EnumLinkedListType.DOUBLE:
|
|
14
|
-
linkedList = new DoubleLinkedList(capacity);
|
|
15
|
-
break;
|
|
16
|
-
case EnumLinkedListType.SINGLE:
|
|
17
|
-
linkedList = new SingleLinkedList(capacity);
|
|
18
|
-
break;
|
|
19
|
-
default:
|
|
20
|
-
throw new Error("Invalid list type");
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return linkedList;
|
|
24
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Write your code here
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
// import { demoHashtable } from "./demo/demo.hashtable";
|
|
6
|
-
// import { demoBst, demoBstObjects } from "./demo/demo.bst";
|
|
7
|
-
// import { bstCompare } from "./demo/performance/bst-compare";
|
|
8
|
-
// import { demoStack } from "./demo/demo.stack";
|
|
9
|
-
// import { perfQueue, perfStack } from "./demo/performance/ds-compare";
|
|
10
|
-
// import { demoLinkedList } from "./demo/demo.linked-list";
|
|
11
|
-
// import { demoQueue } from "./demo/demo.queue";
|
|
12
|
-
// import {
|
|
13
|
-
// demoDirectedGraph,
|
|
14
|
-
// demoGraphGenerated,
|
|
15
|
-
// demoUndirectedGraph,
|
|
16
|
-
// } from "./demo/demo.graph";
|
|
17
|
-
// import { demoLoopedArray } from "./demo/demo.looped-array";
|
|
18
|
-
// import { compareAllSortTypes } from "./demo/performance/sort-compare";
|
|
19
|
-
//
|
|
20
|
-
// demoLinkedList();
|
|
21
|
-
// // console.log("================================================================");
|
|
22
|
-
// demoLoopedArray();
|
|
23
|
-
// // console.log("================================================================");
|
|
24
|
-
// demoQueue();
|
|
25
|
-
// // console.log("================================================================");
|
|
26
|
-
// demoStack();
|
|
27
|
-
// // console.log("================================================================");
|
|
28
|
-
// demoUndirectedGraph();
|
|
29
|
-
// // console.log("================================================================");
|
|
30
|
-
// demoDirectedGraph();
|
|
31
|
-
// // console.log("================================================================");
|
|
32
|
-
// demoGraphGenerated();
|
|
33
|
-
// // console.log("================================================================");
|
|
34
|
-
// compareAllSortTypes();
|
|
35
|
-
// // console.log("===========================================================");
|
|
36
|
-
// perfQueue();
|
|
37
|
-
// // console.log("===========================================================");
|
|
38
|
-
// perfStack();
|
|
39
|
-
// // console.log("===========================================================");
|
|
40
|
-
// demoBst();
|
|
41
|
-
// // console.log("===========================================================");
|
|
42
|
-
// bstCompare();
|
|
43
|
-
// // console.log("===========================================================");
|
|
44
|
-
// demoHashtable();
|
package/src/types/ArrayMatrix.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type ArrayMatrix = Array<Array<number>>;
|