data-structure-typed 1.21.4 → 1.32.0
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/.auto-changelog +9 -0
- package/.auto-changelog-template.hbs +36 -0
- package/.eslintrc.js +61 -0
- package/.gitattributes +112 -0
- package/.github/workflows/ci.yml +30 -0
- package/.prettierignore +6 -0
- package/.prettierrc.js +16 -0
- package/CHANGELOG.md +17 -0
- package/CODE-OF-CONDUCT.md +80 -0
- package/COMMANDS.md +28 -0
- package/README.md +147 -95
- package/SECURITY.md +15 -0
- package/coverage/clover.xml +3393 -0
- package/coverage/coverage-final.json +67 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +386 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/aa-tree.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/abstract-binary-tree.ts.html +4966 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/avl-tree.ts.html +1015 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/b-tree.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/binary-indexed-tree.ts.html +313 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/binary-tree.ts.html +226 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/bst.ts.html +1714 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/index.html +296 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/index.ts.html +121 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/rb-tree.ts.html +388 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/segment-tree.ts.html +811 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/splay-tree.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/tree-multiset.ts.html +2185 -0
- package/coverage/lcov-report/src/data-structures/binary-tree/two-three-tree.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/graph/abstract-graph.ts.html +3205 -0
- package/coverage/lcov-report/src/data-structures/graph/directed-graph.ts.html +1495 -0
- package/coverage/lcov-report/src/data-structures/graph/index.html +176 -0
- package/coverage/lcov-report/src/data-structures/graph/index.ts.html +97 -0
- package/coverage/lcov-report/src/data-structures/graph/map-graph.ts.html +472 -0
- package/coverage/lcov-report/src/data-structures/graph/undirected-graph.ts.html +907 -0
- package/coverage/lcov-report/src/data-structures/hash/coordinate-map.ts.html +286 -0
- package/coverage/lcov-report/src/data-structures/hash/coordinate-set.ts.html +253 -0
- package/coverage/lcov-report/src/data-structures/hash/hash-table.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/hash/index.html +206 -0
- package/coverage/lcov-report/src/data-structures/hash/index.ts.html +103 -0
- package/coverage/lcov-report/src/data-structures/hash/pair.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/hash/tree-map.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/hash/tree-set.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/heap/heap.ts.html +721 -0
- package/coverage/lcov-report/src/data-structures/heap/index.html +161 -0
- package/coverage/lcov-report/src/data-structures/heap/index.ts.html +94 -0
- package/coverage/lcov-report/src/data-structures/heap/max-heap.ts.html +178 -0
- package/coverage/lcov-report/src/data-structures/heap/min-heap.ts.html +181 -0
- package/coverage/lcov-report/src/data-structures/index.html +116 -0
- package/coverage/lcov-report/src/data-structures/index.ts.html +118 -0
- package/coverage/lcov-report/src/data-structures/linked-list/doubly-linked-list.ts.html +1804 -0
- package/coverage/lcov-report/src/data-structures/linked-list/index.html +161 -0
- package/coverage/lcov-report/src/data-structures/linked-list/index.ts.html +94 -0
- package/coverage/lcov-report/src/data-structures/linked-list/singly-linked-list.ts.html +1588 -0
- package/coverage/lcov-report/src/data-structures/linked-list/skip-linked-list.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/matrix/index.html +176 -0
- package/coverage/lcov-report/src/data-structures/matrix/index.ts.html +97 -0
- package/coverage/lcov-report/src/data-structures/matrix/matrix.ts.html +166 -0
- package/coverage/lcov-report/src/data-structures/matrix/matrix2d.ts.html +721 -0
- package/coverage/lcov-report/src/data-structures/matrix/navigator.ts.html +448 -0
- package/coverage/lcov-report/src/data-structures/matrix/vector2d.ts.html +1033 -0
- package/coverage/lcov-report/src/data-structures/priority-queue/index.html +161 -0
- package/coverage/lcov-report/src/data-structures/priority-queue/index.ts.html +94 -0
- package/coverage/lcov-report/src/data-structures/priority-queue/max-priority-queue.ts.html +253 -0
- package/coverage/lcov-report/src/data-structures/priority-queue/min-priority-queue.ts.html +256 -0
- package/coverage/lcov-report/src/data-structures/priority-queue/priority-queue.ts.html +1162 -0
- package/coverage/lcov-report/src/data-structures/queue/deque.ts.html +976 -0
- package/coverage/lcov-report/src/data-structures/queue/index.html +146 -0
- package/coverage/lcov-report/src/data-structures/queue/index.ts.html +91 -0
- package/coverage/lcov-report/src/data-structures/queue/queue.ts.html +658 -0
- package/coverage/lcov-report/src/data-structures/stack/index.html +131 -0
- package/coverage/lcov-report/src/data-structures/stack/index.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/stack/stack.ts.html +379 -0
- package/coverage/lcov-report/src/data-structures/tree/index.html +131 -0
- package/coverage/lcov-report/src/data-structures/tree/index.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/tree/tree.ts.html +292 -0
- package/coverage/lcov-report/src/data-structures/trie/index.html +131 -0
- package/coverage/lcov-report/src/data-structures/trie/index.ts.html +88 -0
- package/coverage/lcov-report/src/data-structures/trie/trie.ts.html +760 -0
- package/coverage/lcov-report/src/index.html +116 -0
- package/coverage/lcov-report/src/index.ts.html +97 -0
- package/coverage/lcov-report/src/interfaces/index.html +116 -0
- package/coverage/lcov-report/src/interfaces/index.ts.html +130 -0
- package/coverage/lcov-report/src/types/data-structures/abstract-binary-tree.ts.html +235 -0
- package/coverage/lcov-report/src/types/data-structures/bst.ts.html +124 -0
- package/coverage/lcov-report/src/types/data-structures/directed-graph.ts.html +109 -0
- package/coverage/lcov-report/src/types/data-structures/index.html +176 -0
- package/coverage/lcov-report/src/types/data-structures/index.ts.html +130 -0
- package/coverage/lcov-report/src/types/data-structures/rb-tree.ts.html +106 -0
- package/coverage/lcov-report/src/types/index.html +116 -0
- package/coverage/lcov-report/src/types/index.ts.html +94 -0
- package/coverage/lcov-report/src/types/utils/index.html +116 -0
- package/coverage/lcov-report/src/types/utils/index.ts.html +91 -0
- package/coverage/lcov-report/src/utils/index.html +131 -0
- package/coverage/lcov-report/src/utils/index.ts.html +88 -0
- package/coverage/lcov-report/src/utils/utils.ts.html +322 -0
- package/coverage/lcov-report/test/utils/index.html +146 -0
- package/coverage/lcov-report/test/utils/index.ts.html +91 -0
- package/coverage/lcov-report/test/utils/magnitude.ts.html +148 -0
- package/coverage/lcov-report/test/utils/number.ts.html +94 -0
- package/coverage/lcov.info +6676 -0
- package/dist/data-structures/binary-tree/aa-tree.js +6 -2
- package/dist/data-structures/binary-tree/aa-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +398 -672
- package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/avl-tree.js +122 -151
- package/dist/data-structures/binary-tree/avl-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/b-tree.js +6 -2
- package/dist/data-structures/binary-tree/b-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +24 -54
- package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/binary-tree.js +31 -32
- package/dist/data-structures/binary-tree/binary-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/bst.js +266 -208
- package/dist/data-structures/binary-tree/bst.js.map +1 -0
- package/dist/data-structures/binary-tree/index.js +1 -0
- package/dist/data-structures/binary-tree/index.js.map +1 -0
- package/dist/data-structures/binary-tree/rb-tree.js +46 -37
- package/dist/data-structures/binary-tree/rb-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/segment-tree.js +124 -127
- package/dist/data-structures/binary-tree/segment-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/splay-tree.js +6 -2
- package/dist/data-structures/binary-tree/splay-tree.js.map +1 -0
- package/dist/data-structures/binary-tree/tree-multiset.js +227 -354
- package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -0
- package/dist/data-structures/binary-tree/two-three-tree.js +6 -2
- package/dist/data-structures/binary-tree/two-three-tree.js.map +1 -0
- package/dist/data-structures/graph/abstract-graph.js +582 -609
- package/dist/data-structures/graph/abstract-graph.js.map +1 -0
- package/dist/data-structures/graph/directed-graph.js +276 -312
- package/dist/data-structures/graph/directed-graph.js.map +1 -0
- package/dist/data-structures/graph/index.js +1 -0
- package/dist/data-structures/graph/index.js.map +1 -0
- package/dist/data-structures/graph/map-graph.js +88 -100
- package/dist/data-structures/graph/map-graph.js.map +1 -0
- package/dist/data-structures/graph/undirected-graph.js +180 -195
- package/dist/data-structures/graph/undirected-graph.js.map +1 -0
- package/dist/data-structures/hash/coordinate-map.js +46 -58
- package/dist/data-structures/hash/coordinate-map.js.map +1 -0
- package/dist/data-structures/hash/coordinate-set.js +43 -48
- package/dist/data-structures/hash/coordinate-set.js.map +1 -0
- package/dist/data-structures/hash/hash-table.js +6 -2
- package/dist/data-structures/hash/hash-table.js.map +1 -0
- package/dist/data-structures/hash/index.js +1 -0
- package/dist/data-structures/hash/index.js.map +1 -0
- package/dist/data-structures/hash/pair.js +6 -2
- package/dist/data-structures/hash/pair.js.map +1 -0
- package/dist/data-structures/hash/tree-map.js +6 -2
- package/dist/data-structures/hash/tree-map.js.map +1 -0
- package/dist/data-structures/hash/tree-set.js +6 -2
- package/dist/data-structures/hash/tree-set.js.map +1 -0
- package/dist/data-structures/heap/heap.js +83 -120
- package/dist/data-structures/heap/heap.js.map +1 -0
- package/dist/data-structures/heap/index.js +1 -0
- package/dist/data-structures/heap/index.js.map +1 -0
- package/dist/data-structures/heap/max-heap.js +27 -24
- package/dist/data-structures/heap/max-heap.js.map +1 -0
- package/dist/data-structures/heap/min-heap.js +27 -25
- package/dist/data-structures/heap/min-heap.js.map +1 -0
- package/dist/data-structures/index.js +1 -0
- package/dist/data-structures/index.js.map +1 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js +202 -307
- package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -0
- package/dist/data-structures/linked-list/index.js +1 -0
- package/dist/data-structures/linked-list/index.js.map +1 -0
- package/dist/data-structures/linked-list/singly-linked-list.js +223 -251
- package/dist/data-structures/linked-list/singly-linked-list.js.map +1 -0
- package/dist/data-structures/linked-list/skip-linked-list.js +6 -2
- package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -0
- package/dist/data-structures/matrix/index.js +1 -0
- package/dist/data-structures/matrix/index.js.map +1 -0
- package/dist/data-structures/matrix/matrix.js +9 -22
- package/dist/data-structures/matrix/matrix.js.map +1 -0
- package/dist/data-structures/matrix/matrix2d.js +75 -149
- package/dist/data-structures/matrix/matrix2d.js.map +1 -0
- package/dist/data-structures/matrix/navigator.js +38 -46
- package/dist/data-structures/matrix/navigator.js.map +1 -0
- package/dist/data-structures/matrix/vector2d.js +90 -254
- package/dist/data-structures/matrix/vector2d.js.map +1 -0
- package/dist/data-structures/priority-queue/index.js +1 -0
- package/dist/data-structures/priority-queue/index.js.map +1 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +47 -32
- package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +47 -33
- package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -0
- package/dist/data-structures/priority-queue/priority-queue.js +150 -241
- package/dist/data-structures/priority-queue/priority-queue.js.map +1 -0
- package/dist/data-structures/queue/deque.js +130 -162
- package/dist/data-structures/queue/deque.js.map +1 -0
- package/dist/data-structures/queue/index.js +1 -0
- package/dist/data-structures/queue/index.js.map +1 -0
- package/dist/data-structures/queue/queue.js +181 -100
- package/dist/data-structures/queue/queue.js.map +1 -0
- package/dist/data-structures/stack/index.js +1 -0
- package/dist/data-structures/stack/index.js.map +1 -0
- package/dist/data-structures/stack/stack.js +23 -71
- package/dist/data-structures/stack/stack.js.map +1 -0
- package/dist/data-structures/tree/index.js +1 -0
- package/dist/data-structures/tree/index.js.map +1 -0
- package/dist/data-structures/tree/tree.js +46 -33
- package/dist/data-structures/tree/tree.js.map +1 -0
- package/dist/data-structures/trie/index.js +1 -0
- package/dist/data-structures/trie/index.js.map +1 -0
- package/dist/data-structures/trie/trie.js +201 -129
- package/dist/data-structures/trie/trie.js.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/abstract-binary-tree.js +1 -0
- package/dist/interfaces/abstract-binary-tree.js.map +1 -0
- package/dist/interfaces/abstract-graph.js +1 -0
- package/dist/interfaces/abstract-graph.js.map +1 -0
- package/dist/interfaces/avl-tree.js +1 -0
- package/dist/interfaces/avl-tree.js.map +1 -0
- package/dist/interfaces/binary-tree.js +1 -0
- package/dist/interfaces/binary-tree.js.map +1 -0
- package/dist/interfaces/bst.js +1 -0
- package/dist/interfaces/bst.js.map +1 -0
- package/dist/interfaces/directed-graph.js +1 -0
- package/dist/interfaces/directed-graph.js.map +1 -0
- package/dist/interfaces/doubly-linked-list.js +1 -0
- package/dist/interfaces/doubly-linked-list.js.map +1 -0
- package/dist/interfaces/heap.js +1 -0
- package/dist/interfaces/heap.js.map +1 -0
- package/dist/interfaces/index.js +1 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/interfaces/navigator.js +1 -0
- package/dist/interfaces/navigator.js.map +1 -0
- package/dist/interfaces/priority-queue.js +1 -0
- package/dist/interfaces/priority-queue.js.map +1 -0
- package/dist/interfaces/rb-tree.js +1 -0
- package/dist/interfaces/rb-tree.js.map +1 -0
- package/dist/interfaces/segment-tree.js +1 -0
- package/dist/interfaces/segment-tree.js.map +1 -0
- package/dist/interfaces/singly-linked-list.js +1 -0
- package/dist/interfaces/singly-linked-list.js.map +1 -0
- package/dist/interfaces/tree-multiset.js +1 -0
- package/dist/interfaces/tree-multiset.js.map +1 -0
- package/dist/interfaces/undirected-graph.js +1 -0
- package/dist/interfaces/undirected-graph.js.map +1 -0
- package/dist/types/data-structures/abstract-binary-tree.js +1 -7
- package/dist/types/data-structures/abstract-binary-tree.js.map +1 -0
- package/dist/types/data-structures/abstract-graph.js +1 -0
- package/dist/types/data-structures/abstract-graph.js.map +1 -0
- package/dist/types/data-structures/avl-tree.js +1 -0
- package/dist/types/data-structures/avl-tree.js.map +1 -0
- package/dist/types/data-structures/binary-tree.js +1 -0
- package/dist/types/data-structures/binary-tree.js.map +1 -0
- package/dist/types/data-structures/bst.js +1 -0
- package/dist/types/data-structures/bst.js.map +1 -0
- package/dist/types/data-structures/directed-graph.js +1 -0
- package/dist/types/data-structures/directed-graph.js.map +1 -0
- package/dist/types/data-structures/doubly-linked-list.js +1 -0
- package/dist/types/data-structures/doubly-linked-list.js.map +1 -0
- package/dist/types/data-structures/heap.js +1 -0
- package/dist/types/data-structures/heap.js.map +1 -0
- package/dist/types/data-structures/index.js +1 -0
- package/dist/types/data-structures/index.js.map +1 -0
- package/dist/types/data-structures/map-graph.js +1 -0
- package/dist/types/data-structures/map-graph.js.map +1 -0
- package/dist/types/data-structures/navigator.js +1 -0
- package/dist/types/data-structures/navigator.js.map +1 -0
- package/dist/types/data-structures/priority-queue.js +1 -0
- package/dist/types/data-structures/priority-queue.js.map +1 -0
- package/dist/types/data-structures/rb-tree.js +1 -0
- package/dist/types/data-structures/rb-tree.js.map +1 -0
- package/dist/types/data-structures/segment-tree.js +1 -0
- package/dist/types/data-structures/segment-tree.js.map +1 -0
- package/dist/types/data-structures/singly-linked-list.js +1 -0
- package/dist/types/data-structures/singly-linked-list.js.map +1 -0
- package/dist/types/data-structures/tree-multiset.js +1 -0
- package/dist/types/data-structures/tree-multiset.js.map +1 -0
- package/dist/types/helpers.js +1 -0
- package/dist/types/helpers.js.map +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/utils/index.js +1 -0
- package/dist/types/utils/index.js.map +1 -0
- package/dist/types/utils/utils.js +1 -0
- package/dist/types/utils/utils.js.map +1 -0
- package/dist/types/utils/validate-type.js +1 -0
- package/dist/types/utils/validate-type.js.map +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/utils.js +108 -22
- package/dist/utils/utils.js.map +1 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +127 -0
- package/docs/assets/main.js +58 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1367 -0
- package/docs/classes/AVLTree.html +2182 -0
- package/docs/classes/AVLTreeNode.html +399 -0
- package/docs/classes/AaTree.html +202 -0
- package/docs/classes/AbstractBinaryTree.html +1836 -0
- package/docs/classes/AbstractBinaryTreeNode.html +441 -0
- package/docs/classes/AbstractEdge.html +345 -0
- package/docs/classes/AbstractGraph.html +1105 -0
- package/docs/classes/AbstractVertex.html +299 -0
- package/docs/classes/ArrayDeque.html +469 -0
- package/docs/classes/BST.html +2026 -0
- package/docs/classes/BSTNode.html +400 -0
- package/docs/classes/BTree.html +202 -0
- package/docs/classes/BinaryIndexedTree.html +371 -0
- package/docs/classes/BinaryTree.html +1867 -0
- package/docs/classes/BinaryTreeNode.html +399 -0
- package/docs/classes/Character.html +250 -0
- package/docs/classes/CoordinateMap.html +513 -0
- package/docs/classes/CoordinateSet.html +474 -0
- package/docs/classes/Deque.html +1005 -0
- package/docs/classes/DirectedEdge.html +404 -0
- package/docs/classes/DirectedGraph.html +1530 -0
- package/docs/classes/DirectedVertex.html +286 -0
- package/docs/classes/DoublyLinkedList.html +998 -0
- package/docs/classes/DoublyLinkedListNode.html +327 -0
- package/docs/classes/HashTable.html +202 -0
- package/docs/classes/Heap.html +647 -0
- package/docs/classes/HeapItem.html +296 -0
- package/docs/classes/LinkedListQueue.html +884 -0
- package/docs/classes/MapEdge.html +391 -0
- package/docs/classes/MapGraph.html +1583 -0
- package/docs/classes/MapVertex.html +356 -0
- package/docs/classes/Matrix2D.html +532 -0
- package/docs/classes/MatrixNTI2D.html +270 -0
- package/docs/classes/MaxHeap.html +671 -0
- package/docs/classes/MaxPriorityQueue.html +866 -0
- package/docs/classes/MinHeap.html +672 -0
- package/docs/classes/MinPriorityQueue.html +868 -0
- package/docs/classes/Navigator.html +343 -0
- package/docs/classes/ObjectDeque.html +527 -0
- package/docs/classes/Pair.html +202 -0
- package/docs/classes/PriorityQueue.html +790 -0
- package/docs/classes/Queue.html +521 -0
- package/docs/classes/RBTree.html +2024 -0
- package/docs/classes/RBTreeNode.html +431 -0
- package/docs/classes/SegmentTree.html +464 -0
- package/docs/classes/SegmentTreeNode.html +387 -0
- package/docs/classes/SinglyLinkedList.html +830 -0
- package/docs/classes/SinglyLinkedListNode.html +300 -0
- package/docs/classes/SkipLinkedList.html +202 -0
- package/docs/classes/SplayTree.html +202 -0
- package/docs/classes/Stack.html +398 -0
- package/docs/classes/TreeMap.html +202 -0
- package/docs/classes/TreeMultiset.html +2510 -0
- package/docs/classes/TreeMultisetNode.html +447 -0
- package/docs/classes/TreeNode.html +344 -0
- package/docs/classes/TreeSet.html +202 -0
- package/docs/classes/Trie.html +402 -0
- package/docs/classes/TrieNode.html +310 -0
- package/docs/classes/TwoThreeTree.html +202 -0
- package/docs/classes/UndirectedEdge.html +374 -0
- package/docs/classes/UndirectedGraph.html +1285 -0
- package/docs/classes/UndirectedVertex.html +284 -0
- package/docs/classes/Vector2D.html +835 -0
- package/docs/enums/CP.html +211 -0
- package/docs/enums/FamilyPosition.html +239 -0
- package/docs/enums/LoopType.html +212 -0
- package/docs/enums/RBColor.html +204 -0
- package/docs/enums/TopologicalProperty.html +211 -0
- package/docs/functions/arrayRemove.html +208 -0
- package/docs/functions/isThunk.html +186 -0
- package/docs/functions/toThunk.html +186 -0
- package/docs/functions/trampoline.html +186 -0
- package/docs/functions/trampolineAsync.html +186 -0
- package/docs/functions/uuidV4.html +181 -0
- package/docs/index.html +693 -0
- package/docs/interfaces/IAVLTree.html +1245 -0
- package/docs/interfaces/IAbstractBinaryTree.html +1101 -0
- package/docs/interfaces/IAbstractBinaryTreeNode.html +335 -0
- package/docs/interfaces/IAbstractGraph.html +433 -0
- package/docs/interfaces/IBST.html +1245 -0
- package/docs/interfaces/IDirectedGraph.html +570 -0
- package/docs/interfaces/IRBTree.html +1247 -0
- package/docs/interfaces/IUNDirectedGraph.html +463 -0
- package/docs/modules.html +328 -0
- package/docs/types/AVLTreeNodeNested.html +182 -0
- package/docs/types/AVLTreeOptions.html +180 -0
- package/docs/types/AbstractBinaryTreeNodeNested.html +182 -0
- package/docs/types/AbstractBinaryTreeNodeProperties.html +182 -0
- package/docs/types/AbstractBinaryTreeNodeProperty.html +182 -0
- package/docs/types/AbstractBinaryTreeOptions.html +182 -0
- package/docs/types/BSTComparator.html +192 -0
- package/docs/types/BSTNodeNested.html +182 -0
- package/docs/types/BSTOptions.html +182 -0
- package/docs/types/BinaryTreeDeletedResult.html +189 -0
- package/docs/types/BinaryTreeNodeId.html +177 -0
- package/docs/types/BinaryTreeNodeNested.html +182 -0
- package/docs/types/BinaryTreeNodePropertyName.html +177 -0
- package/docs/types/BinaryTreeOptions.html +180 -0
- package/docs/types/DFSOrderPattern.html +177 -0
- package/docs/types/DijkstraResult.html +199 -0
- package/docs/types/Direction.html +177 -0
- package/docs/types/DummyAny.html +190 -0
- package/docs/types/EdgeId.html +177 -0
- package/docs/types/HeapOptions.html +198 -0
- package/docs/types/IAVLTreeNode.html +184 -0
- package/docs/types/IBSTNode.html +184 -0
- package/docs/types/IBinaryTree.html +182 -0
- package/docs/types/IBinaryTreeNode.html +184 -0
- package/docs/types/IRBTreeNode.html +184 -0
- package/docs/types/ITreeMultiset.html +182 -0
- package/docs/types/ITreeMultisetNode.html +184 -0
- package/docs/types/KeyValueObject.html +182 -0
- package/docs/types/KeyValueObjectWithId.html +184 -0
- package/docs/types/MapGraphCoordinate.html +177 -0
- package/docs/types/NavigatorParams.html +211 -0
- package/docs/types/NodeOrPropertyName.html +177 -0
- package/docs/types/NonNumberNonObjectButDefined.html +177 -0
- package/docs/types/ObjectWithNonNumberId.html +184 -0
- package/docs/types/ObjectWithNumberId.html +184 -0
- package/docs/types/ObjectWithoutId.html +177 -0
- package/docs/types/PriorityQueueComparator.html +197 -0
- package/docs/types/PriorityQueueDFSOrderPattern.html +177 -0
- package/docs/types/PriorityQueueOptions.html +191 -0
- package/docs/types/RBTreeNodeNested.html +182 -0
- package/docs/types/RBTreeOptions.html +180 -0
- package/docs/types/RestrictValById.html +177 -0
- package/docs/types/SegmentTreeNodeVal.html +177 -0
- package/docs/types/SpecifyOptional.html +184 -0
- package/docs/types/Thunk.html +185 -0
- package/docs/types/ToThunkFn.html +185 -0
- package/docs/types/TopologicalStatus.html +177 -0
- package/docs/types/TreeMultisetNodeNested.html +182 -0
- package/docs/types/TreeMultisetOptions.html +180 -0
- package/docs/types/TrlAsyncFn.html +190 -0
- package/docs/types/TrlFn.html +190 -0
- package/docs/types/Turning.html +177 -0
- package/docs/types/VertexId.html +177 -0
- package/docs/variables/THUNK_SYMBOL.html +177 -0
- package/jest.config.js +7 -0
- package/lib/data-structures/binary-tree/aa-tree.js +2 -0
- package/{dist → lib}/data-structures/binary-tree/abstract-binary-tree.d.ts +194 -22
- package/lib/data-structures/binary-tree/abstract-binary-tree.js +1291 -0
- package/{dist → lib}/data-structures/binary-tree/avl-tree.d.ts +12 -12
- package/lib/data-structures/binary-tree/avl-tree.js +311 -0
- package/lib/data-structures/binary-tree/b-tree.js +2 -0
- package/lib/data-structures/binary-tree/binary-indexed-tree.js +69 -0
- package/lib/data-structures/binary-tree/binary-tree.js +35 -0
- package/{dist → lib}/data-structures/binary-tree/bst.d.ts +19 -8
- package/lib/data-structures/binary-tree/bst.js +551 -0
- package/lib/data-structures/binary-tree/index.js +12 -0
- package/{dist → lib}/data-structures/binary-tree/rb-tree.d.ts +0 -6
- package/lib/data-structures/binary-tree/rb-tree.js +22 -0
- package/lib/data-structures/binary-tree/segment-tree.js +210 -0
- package/lib/data-structures/binary-tree/splay-tree.js +2 -0
- package/{dist → lib}/data-structures/binary-tree/tree-multiset.d.ts +20 -23
- package/lib/data-structures/binary-tree/tree-multiset.js +673 -0
- package/lib/data-structures/binary-tree/two-three-tree.js +2 -0
- package/lib/data-structures/graph/abstract-graph.js +918 -0
- package/lib/data-structures/graph/directed-graph.js +416 -0
- package/lib/data-structures/graph/index.js +4 -0
- package/lib/data-structures/graph/map-graph.js +105 -0
- package/lib/data-structures/graph/undirected-graph.js +246 -0
- package/lib/data-structures/hash/coordinate-map.js +61 -0
- package/lib/data-structures/hash/coordinate-set.js +51 -0
- package/lib/data-structures/hash/hash-table.js +2 -0
- package/lib/data-structures/hash/index.js +6 -0
- package/lib/data-structures/hash/pair.js +2 -0
- package/lib/data-structures/hash/tree-map.js +2 -0
- package/lib/data-structures/hash/tree-set.js +2 -0
- package/lib/data-structures/heap/heap.js +152 -0
- package/lib/data-structures/heap/index.js +3 -0
- package/lib/data-structures/heap/max-heap.js +26 -0
- package/lib/data-structures/heap/min-heap.js +27 -0
- package/lib/data-structures/index.js +11 -0
- package/{dist → lib}/data-structures/linked-list/doubly-linked-list.d.ts +5 -5
- package/lib/data-structures/linked-list/doubly-linked-list.js +521 -0
- package/lib/data-structures/linked-list/index.js +3 -0
- package/{dist → lib}/data-structures/linked-list/singly-linked-list.d.ts +6 -5
- package/lib/data-structures/linked-list/singly-linked-list.js +443 -0
- package/lib/data-structures/linked-list/skip-linked-list.js +2 -0
- package/lib/data-structures/matrix/index.js +4 -0
- package/lib/data-structures/matrix/matrix.js +24 -0
- package/lib/data-structures/matrix/matrix2d.js +195 -0
- package/lib/data-structures/matrix/navigator.js +101 -0
- package/lib/data-structures/matrix/vector2d.js +287 -0
- package/lib/data-structures/priority-queue/index.js +3 -0
- package/lib/data-structures/priority-queue/max-priority-queue.js +39 -0
- package/lib/data-structures/priority-queue/min-priority-queue.js +40 -0
- package/lib/data-structures/priority-queue/priority-queue.js +317 -0
- package/{dist → lib}/data-structures/queue/deque.d.ts +45 -0
- package/lib/data-structures/queue/deque.js +270 -0
- package/lib/data-structures/queue/index.js +2 -0
- package/{dist → lib}/data-structures/queue/queue.d.ts +47 -13
- package/lib/data-structures/queue/queue.js +165 -0
- package/lib/data-structures/stack/index.js +1 -0
- package/lib/data-structures/stack/stack.js +87 -0
- package/lib/data-structures/tree/index.js +1 -0
- package/lib/data-structures/tree/tree.js +56 -0
- package/lib/data-structures/trie/index.js +1 -0
- package/lib/data-structures/trie/trie.js +205 -0
- package/lib/index.js +4 -0
- package/{dist → lib}/interfaces/avl-tree.d.ts +1 -9
- package/lib/interfaces/binary-tree.d.ts +4 -0
- package/{dist → lib}/interfaces/bst.d.ts +1 -2
- package/lib/interfaces/heap.js +1 -0
- package/lib/interfaces/index.js +15 -0
- package/lib/interfaces/navigator.d.ts +1 -0
- package/lib/interfaces/navigator.js +1 -0
- package/lib/interfaces/priority-queue.d.ts +1 -0
- package/lib/interfaces/priority-queue.js +1 -0
- package/{dist → lib}/interfaces/rb-tree.d.ts +1 -2
- package/lib/interfaces/rb-tree.js +1 -0
- package/lib/interfaces/segment-tree.d.ts +1 -0
- package/lib/interfaces/segment-tree.js +1 -0
- package/lib/interfaces/singly-linked-list.d.ts +1 -0
- package/lib/interfaces/singly-linked-list.js +1 -0
- package/lib/interfaces/tree-multiset.d.ts +5 -0
- package/lib/interfaces/tree-multiset.js +1 -0
- package/lib/interfaces/undirected-graph.js +1 -0
- package/{dist → lib}/types/data-structures/abstract-binary-tree.d.ts +1 -1
- package/lib/types/data-structures/abstract-binary-tree.js +22 -0
- package/lib/types/data-structures/abstract-graph.js +1 -0
- package/{dist → lib}/types/data-structures/avl-tree.d.ts +1 -1
- package/lib/types/data-structures/avl-tree.js +1 -0
- package/lib/types/data-structures/binary-tree.js +1 -0
- package/lib/types/data-structures/bst.js +6 -0
- package/lib/types/data-structures/directed-graph.js +6 -0
- package/lib/types/data-structures/doubly-linked-list.d.ts +1 -0
- package/lib/types/data-structures/doubly-linked-list.js +1 -0
- package/lib/types/data-structures/heap.js +1 -0
- package/lib/types/data-structures/index.js +15 -0
- package/lib/types/data-structures/map-graph.js +1 -0
- package/lib/types/data-structures/navigator.js +1 -0
- package/lib/types/data-structures/priority-queue.js +1 -0
- package/lib/types/data-structures/rb-tree.js +5 -0
- package/lib/types/data-structures/segment-tree.js +1 -0
- package/lib/types/data-structures/singly-linked-list.d.ts +1 -0
- package/lib/types/data-structures/singly-linked-list.js +1 -0
- package/lib/types/data-structures/tree-multiset.js +1 -0
- package/lib/types/helpers.d.ts +1 -0
- package/lib/types/helpers.js +1 -0
- package/lib/types/index.js +3 -0
- package/lib/types/utils/index.js +2 -0
- package/{dist → lib}/types/utils/utils.d.ts +1 -1
- package/lib/types/utils/utils.js +1 -0
- package/{dist → lib}/types/utils/validate-type.d.ts +1 -1
- package/lib/types/utils/validate-type.js +1 -0
- package/lib/utils/index.js +1 -0
- package/lib/utils/utils.js +57 -0
- package/package.json +150 -56
- package/rename_clear_files.sh +29 -0
- package/test/integration/avl-tree.test.ts +111 -0
- package/test/integration/bst.test.ts +371 -0
- package/test/integration/heap.test.js +19 -0
- package/test/integration/index.html +44 -0
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +111 -0
- package/test/unit/data-structures/binary-tree/bst.test.ts +371 -0
- package/test/unit/data-structures/binary-tree/overall.test.ts +57 -0
- package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +405 -0
- package/test/unit/data-structures/graph/abstract-graph.test.ts +5 -0
- package/test/unit/data-structures/graph/directed-graph.test.ts +517 -0
- package/test/unit/data-structures/graph/index.ts +2 -0
- package/test/unit/data-structures/graph/map-graph.test.ts +46 -0
- package/test/unit/data-structures/graph/overall.test.ts +50 -0
- package/test/unit/data-structures/graph/undirected-graph.test.ts +60 -0
- package/test/unit/data-structures/heap/heap.test.ts +56 -0
- package/test/unit/data-structures/heap/max-heap.test.ts +42 -0
- package/test/unit/data-structures/heap/min-heap.test.ts +81 -0
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +365 -0
- package/test/unit/data-structures/linked-list/index.ts +4 -0
- package/test/unit/data-structures/linked-list/linked-list.test.ts +37 -0
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +401 -0
- package/test/unit/data-structures/linked-list/skip-linked-list.test.ts +13 -0
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +108 -0
- package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +105 -0
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +27 -0
- package/test/unit/data-structures/queue/queue.test.ts +36 -0
- package/test/utils/index.ts +2 -0
- package/test/utils/magnitude.ts +21 -0
- package/test/utils/number.ts +3 -0
- package/tsconfig.build.json +33 -0
- package/tsconfig.json +38 -0
- package/umd/bundle.min.js +3 -0
- package/umd/bundle.min.js.map +1 -0
- package/webpack.config.js +28 -0
- package/dist/bundle.js +0 -2
- package/dist/interfaces/binary-tree.d.ts +0 -6
- package/dist/interfaces/tree-multiset.d.ts +0 -7
- /package/{dist → lib}/data-structures/binary-tree/aa-tree.d.ts +0 -0
- /package/{dist → lib}/data-structures/binary-tree/b-tree.d.ts +0 -0
- /package/{dist → lib}/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -0
- /package/{dist → lib}/data-structures/binary-tree/binary-tree.d.ts +0 -0
- /package/{dist → lib}/data-structures/binary-tree/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/binary-tree/segment-tree.d.ts +0 -0
- /package/{dist → lib}/data-structures/binary-tree/splay-tree.d.ts +0 -0
- /package/{dist → lib}/data-structures/binary-tree/two-three-tree.d.ts +0 -0
- /package/{dist → lib}/data-structures/graph/abstract-graph.d.ts +0 -0
- /package/{dist → lib}/data-structures/graph/directed-graph.d.ts +0 -0
- /package/{dist → lib}/data-structures/graph/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/graph/map-graph.d.ts +0 -0
- /package/{dist → lib}/data-structures/graph/undirected-graph.d.ts +0 -0
- /package/{dist → lib}/data-structures/hash/coordinate-map.d.ts +0 -0
- /package/{dist → lib}/data-structures/hash/coordinate-set.d.ts +0 -0
- /package/{dist → lib}/data-structures/hash/hash-table.d.ts +0 -0
- /package/{dist → lib}/data-structures/hash/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/hash/pair.d.ts +0 -0
- /package/{dist → lib}/data-structures/hash/tree-map.d.ts +0 -0
- /package/{dist → lib}/data-structures/hash/tree-set.d.ts +0 -0
- /package/{dist → lib}/data-structures/heap/heap.d.ts +0 -0
- /package/{dist → lib}/data-structures/heap/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/heap/max-heap.d.ts +0 -0
- /package/{dist → lib}/data-structures/heap/min-heap.d.ts +0 -0
- /package/{dist → lib}/data-structures/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/linked-list/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/linked-list/skip-linked-list.d.ts +0 -0
- /package/{dist → lib}/data-structures/matrix/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/matrix/matrix.d.ts +0 -0
- /package/{dist → lib}/data-structures/matrix/matrix2d.d.ts +0 -0
- /package/{dist → lib}/data-structures/matrix/navigator.d.ts +0 -0
- /package/{dist → lib}/data-structures/matrix/vector2d.d.ts +0 -0
- /package/{dist → lib}/data-structures/priority-queue/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/priority-queue/max-priority-queue.d.ts +0 -0
- /package/{dist → lib}/data-structures/priority-queue/min-priority-queue.d.ts +0 -0
- /package/{dist → lib}/data-structures/priority-queue/priority-queue.d.ts +0 -0
- /package/{dist → lib}/data-structures/queue/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/stack/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/stack/stack.d.ts +0 -0
- /package/{dist → lib}/data-structures/tree/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/tree/tree.d.ts +0 -0
- /package/{dist → lib}/data-structures/trie/index.d.ts +0 -0
- /package/{dist → lib}/data-structures/trie/trie.d.ts +0 -0
- /package/{dist → lib}/index.d.ts +0 -0
- /package/{dist → lib}/interfaces/abstract-binary-tree.d.ts +0 -0
- /package/{dist/interfaces/doubly-linked-list.d.ts → lib/interfaces/abstract-binary-tree.js} +0 -0
- /package/{dist → lib}/interfaces/abstract-graph.d.ts +0 -0
- /package/{dist/interfaces/heap.d.ts → lib/interfaces/abstract-graph.js} +0 -0
- /package/{dist/interfaces/navigator.d.ts → lib/interfaces/avl-tree.js} +0 -0
- /package/{dist/interfaces/priority-queue.d.ts → lib/interfaces/binary-tree.js} +0 -0
- /package/{dist/interfaces/segment-tree.d.ts → lib/interfaces/bst.js} +0 -0
- /package/{dist → lib}/interfaces/directed-graph.d.ts +0 -0
- /package/{dist/interfaces/singly-linked-list.d.ts → lib/interfaces/directed-graph.js} +0 -0
- /package/{dist/types/data-structures → lib/interfaces}/doubly-linked-list.d.ts +0 -0
- /package/{dist/types/data-structures/singly-linked-list.d.ts → lib/interfaces/doubly-linked-list.js} +0 -0
- /package/{dist/types/helpers.d.ts → lib/interfaces/heap.d.ts} +0 -0
- /package/{dist → lib}/interfaces/index.d.ts +0 -0
- /package/{dist → lib}/interfaces/undirected-graph.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/abstract-graph.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/binary-tree.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/bst.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/directed-graph.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/heap.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/index.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/map-graph.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/navigator.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/priority-queue.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/rb-tree.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/segment-tree.d.ts +0 -0
- /package/{dist → lib}/types/data-structures/tree-multiset.d.ts +0 -0
- /package/{dist → lib}/types/index.d.ts +0 -0
- /package/{dist → lib}/types/utils/index.d.ts +0 -0
- /package/{dist → lib}/utils/index.d.ts +0 -0
- /package/{dist → lib}/utils/utils.d.ts +0 -0
- /package/{dist/bundle.js.LICENSE.txt → umd/bundle.min.js.LICENSE.txt} +0 -0
|
@@ -1,87 +1,125 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __values = (this && this.__values) || function(o) {
|
|
3
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
+
if (m) return m.call(o);
|
|
5
|
+
if (o && typeof o.length === "number") return {
|
|
6
|
+
next: function () {
|
|
7
|
+
if (o && i >= o.length) o = void 0;
|
|
8
|
+
return { value: o && o[i++], done: !o };
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
+
};
|
|
13
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
+
if (!m) return o;
|
|
16
|
+
var i = m.call(o), r, ar = [], e;
|
|
17
|
+
try {
|
|
18
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
+
}
|
|
20
|
+
catch (error) { e = { error: error }; }
|
|
21
|
+
finally {
|
|
22
|
+
try {
|
|
23
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
+
}
|
|
25
|
+
finally { if (e) throw e.error; }
|
|
26
|
+
}
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
2
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
30
|
exports.DoublyLinkedList = exports.DoublyLinkedListNode = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
* @author Tyler Zeng
|
|
8
|
-
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
9
|
-
* @license MIT License
|
|
10
|
-
*/
|
|
11
|
-
class DoublyLinkedListNode {
|
|
12
|
-
/**
|
|
13
|
-
* The constructor function initializes the value, next, and previous properties of an object.
|
|
14
|
-
* @param {T} val - The "val" parameter is the value that will be stored in the node. It can be of any data type, as it
|
|
15
|
-
* is defined as a generic type "T".
|
|
16
|
-
*/
|
|
17
|
-
constructor(val) {
|
|
31
|
+
var DoublyLinkedListNode = (function () {
|
|
32
|
+
function DoublyLinkedListNode(val) {
|
|
18
33
|
this._val = val;
|
|
19
34
|
this._next = null;
|
|
20
35
|
this._prev = null;
|
|
21
36
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
Object.defineProperty(DoublyLinkedListNode.prototype, "val", {
|
|
38
|
+
get: function () {
|
|
39
|
+
return this._val;
|
|
40
|
+
},
|
|
41
|
+
set: function (value) {
|
|
42
|
+
this._val = value;
|
|
43
|
+
},
|
|
44
|
+
enumerable: false,
|
|
45
|
+
configurable: true
|
|
46
|
+
});
|
|
47
|
+
Object.defineProperty(DoublyLinkedListNode.prototype, "next", {
|
|
48
|
+
get: function () {
|
|
49
|
+
return this._next;
|
|
50
|
+
},
|
|
51
|
+
set: function (value) {
|
|
52
|
+
this._next = value;
|
|
53
|
+
},
|
|
54
|
+
enumerable: false,
|
|
55
|
+
configurable: true
|
|
56
|
+
});
|
|
57
|
+
Object.defineProperty(DoublyLinkedListNode.prototype, "prev", {
|
|
58
|
+
get: function () {
|
|
59
|
+
return this._prev;
|
|
60
|
+
},
|
|
61
|
+
set: function (value) {
|
|
62
|
+
this._prev = value;
|
|
63
|
+
},
|
|
64
|
+
enumerable: false,
|
|
65
|
+
configurable: true
|
|
66
|
+
});
|
|
67
|
+
return DoublyLinkedListNode;
|
|
68
|
+
}());
|
|
41
69
|
exports.DoublyLinkedListNode = DoublyLinkedListNode;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
* The constructor initializes the linked list with an empty head, tail, and length.
|
|
45
|
-
*/
|
|
46
|
-
constructor() {
|
|
70
|
+
var DoublyLinkedList = (function () {
|
|
71
|
+
function DoublyLinkedList() {
|
|
47
72
|
this._head = null;
|
|
48
73
|
this._tail = null;
|
|
49
74
|
this._length = 0;
|
|
50
75
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
Object.defineProperty(DoublyLinkedList.prototype, "head", {
|
|
77
|
+
get: function () {
|
|
78
|
+
return this._head;
|
|
79
|
+
},
|
|
80
|
+
set: function (value) {
|
|
81
|
+
this._head = value;
|
|
82
|
+
},
|
|
83
|
+
enumerable: false,
|
|
84
|
+
configurable: true
|
|
85
|
+
});
|
|
86
|
+
Object.defineProperty(DoublyLinkedList.prototype, "tail", {
|
|
87
|
+
get: function () {
|
|
88
|
+
return this._tail;
|
|
89
|
+
},
|
|
90
|
+
set: function (value) {
|
|
91
|
+
this._tail = value;
|
|
92
|
+
},
|
|
93
|
+
enumerable: false,
|
|
94
|
+
configurable: true
|
|
95
|
+
});
|
|
96
|
+
Object.defineProperty(DoublyLinkedList.prototype, "length", {
|
|
97
|
+
get: function () {
|
|
98
|
+
return this._length;
|
|
99
|
+
},
|
|
100
|
+
enumerable: false,
|
|
101
|
+
configurable: true
|
|
102
|
+
});
|
|
103
|
+
DoublyLinkedList.fromArray = function (data) {
|
|
104
|
+
var e_1, _a;
|
|
105
|
+
var doublyLinkedList = new DoublyLinkedList();
|
|
106
|
+
try {
|
|
107
|
+
for (var data_1 = __values(data), data_1_1 = data_1.next(); !data_1_1.done; data_1_1 = data_1.next()) {
|
|
108
|
+
var item = data_1_1.value;
|
|
109
|
+
doublyLinkedList.push(item);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
113
|
+
finally {
|
|
114
|
+
try {
|
|
115
|
+
if (data_1_1 && !data_1_1.done && (_a = data_1.return)) _a.call(data_1);
|
|
116
|
+
}
|
|
117
|
+
finally { if (e_1) throw e_1.error; }
|
|
76
118
|
}
|
|
77
119
|
return doublyLinkedList;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
* @param {T} val - The value to be added to the linked list.
|
|
82
|
-
*/
|
|
83
|
-
push(val) {
|
|
84
|
-
const newNode = new DoublyLinkedListNode(val);
|
|
120
|
+
};
|
|
121
|
+
DoublyLinkedList.prototype.push = function (val) {
|
|
122
|
+
var newNode = new DoublyLinkedListNode(val);
|
|
85
123
|
if (!this.head) {
|
|
86
124
|
this.head = newNode;
|
|
87
125
|
this.tail = newNode;
|
|
@@ -92,16 +130,11 @@ class DoublyLinkedList {
|
|
|
92
130
|
this.tail = newNode;
|
|
93
131
|
}
|
|
94
132
|
this._length++;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
* The `pop()` function removes and returns the value of the last node in a doubly linked list.
|
|
98
|
-
* @returns The method is returning the value of the removed node (removedNode.val) if the list is not empty. If the
|
|
99
|
-
* list is empty, it returns null.
|
|
100
|
-
*/
|
|
101
|
-
pop() {
|
|
133
|
+
};
|
|
134
|
+
DoublyLinkedList.prototype.pop = function () {
|
|
102
135
|
if (!this.tail)
|
|
103
|
-
return
|
|
104
|
-
|
|
136
|
+
return undefined;
|
|
137
|
+
var removedNode = this.tail;
|
|
105
138
|
if (this.head === this.tail) {
|
|
106
139
|
this.head = null;
|
|
107
140
|
this.tail = null;
|
|
@@ -112,16 +145,11 @@ class DoublyLinkedList {
|
|
|
112
145
|
}
|
|
113
146
|
this._length--;
|
|
114
147
|
return removedNode.val;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
* The `shift()` function removes and returns the value of the first node in a doubly linked list.
|
|
118
|
-
* @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
|
|
119
|
-
* list.
|
|
120
|
-
*/
|
|
121
|
-
shift() {
|
|
148
|
+
};
|
|
149
|
+
DoublyLinkedList.prototype.shift = function () {
|
|
122
150
|
if (!this.head)
|
|
123
|
-
return
|
|
124
|
-
|
|
151
|
+
return undefined;
|
|
152
|
+
var removedNode = this.head;
|
|
125
153
|
if (this.head === this.tail) {
|
|
126
154
|
this.head = null;
|
|
127
155
|
this.tail = null;
|
|
@@ -132,14 +160,9 @@ class DoublyLinkedList {
|
|
|
132
160
|
}
|
|
133
161
|
this._length--;
|
|
134
162
|
return removedNode.val;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
* @param {T} val - The `val` parameter represents the value of the new node that will be added to the beginning of the
|
|
139
|
-
* doubly linked list.
|
|
140
|
-
*/
|
|
141
|
-
unshift(val) {
|
|
142
|
-
const newNode = new DoublyLinkedListNode(val);
|
|
163
|
+
};
|
|
164
|
+
DoublyLinkedList.prototype.unshift = function (val) {
|
|
165
|
+
var newNode = new DoublyLinkedListNode(val);
|
|
143
166
|
if (!this.head) {
|
|
144
167
|
this.head = newNode;
|
|
145
168
|
this.tail = newNode;
|
|
@@ -150,49 +173,27 @@ class DoublyLinkedList {
|
|
|
150
173
|
this.head = newNode;
|
|
151
174
|
}
|
|
152
175
|
this._length++;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
* The `getAt` function returns the value at a specified index in a linked list, or null if the index is out of bounds.
|
|
156
|
-
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
157
|
-
* retrieve from the list.
|
|
158
|
-
* @returns The method is returning the value at the specified index in the linked list. If the index is out of bounds
|
|
159
|
-
* or the linked list is empty, it will return null.
|
|
160
|
-
*/
|
|
161
|
-
getAt(index) {
|
|
176
|
+
};
|
|
177
|
+
DoublyLinkedList.prototype.getAt = function (index) {
|
|
162
178
|
if (index < 0 || index >= this.length)
|
|
163
|
-
return
|
|
164
|
-
|
|
165
|
-
for (
|
|
179
|
+
return undefined;
|
|
180
|
+
var current = this.head;
|
|
181
|
+
for (var i = 0; i < index; i++) {
|
|
166
182
|
current = current.next;
|
|
167
183
|
}
|
|
168
184
|
return current.val;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
* The function `getNodeAt` returns the node at a given index in a doubly linked list, or null if the index is out of
|
|
172
|
-
* range.
|
|
173
|
-
* @param {number} index - The `index` parameter is a number that represents the position of the node we want to
|
|
174
|
-
* retrieve from the doubly linked list. It indicates the zero-based index of the node we want to access.
|
|
175
|
-
* @returns The method `getNodeAt(index: number)` returns a `DoublyLinkedListNode<T>` object if the index is within the
|
|
176
|
-
* valid range of the linked list, otherwise it returns `null`.
|
|
177
|
-
*/
|
|
178
|
-
getNodeAt(index) {
|
|
185
|
+
};
|
|
186
|
+
DoublyLinkedList.prototype.getNodeAt = function (index) {
|
|
179
187
|
if (index < 0 || index >= this.length)
|
|
180
188
|
return null;
|
|
181
|
-
|
|
182
|
-
for (
|
|
189
|
+
var current = this.head;
|
|
190
|
+
for (var i = 0; i < index; i++) {
|
|
183
191
|
current = current.next;
|
|
184
192
|
}
|
|
185
193
|
return current;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
* node if found, otherwise it returns null.
|
|
190
|
-
* @param {T} val - The `val` parameter is the value that we want to search for in the doubly linked list.
|
|
191
|
-
* @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<T>` if a node with the specified value `val`
|
|
192
|
-
* is found in the linked list. If no such node is found, it returns `null`.
|
|
193
|
-
*/
|
|
194
|
-
findNode(val) {
|
|
195
|
-
let current = this.head;
|
|
194
|
+
};
|
|
195
|
+
DoublyLinkedList.prototype.findNode = function (val) {
|
|
196
|
+
var current = this.head;
|
|
196
197
|
while (current) {
|
|
197
198
|
if (current.val === val) {
|
|
198
199
|
return current;
|
|
@@ -200,17 +201,8 @@ class DoublyLinkedList {
|
|
|
200
201
|
current = current.next;
|
|
201
202
|
}
|
|
202
203
|
return null;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
* The `insert` function inserts a value at a specified index in a doubly linked list.
|
|
206
|
-
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
207
|
-
* DoublyLinkedList. It is of type number.
|
|
208
|
-
* @param {T} val - The `val` parameter represents the value that you want to insert into the Doubly Linked List at the
|
|
209
|
-
* specified index.
|
|
210
|
-
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
|
|
211
|
-
* if the index is out of bounds.
|
|
212
|
-
*/
|
|
213
|
-
insertAt(index, val) {
|
|
204
|
+
};
|
|
205
|
+
DoublyLinkedList.prototype.insertAt = function (index, val) {
|
|
214
206
|
if (index < 0 || index > this.length)
|
|
215
207
|
return false;
|
|
216
208
|
if (index === 0) {
|
|
@@ -221,47 +213,33 @@ class DoublyLinkedList {
|
|
|
221
213
|
this.push(val);
|
|
222
214
|
return true;
|
|
223
215
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
216
|
+
var newNode = new DoublyLinkedListNode(val);
|
|
217
|
+
var prevNode = this.getNodeAt(index - 1);
|
|
218
|
+
var nextNode = prevNode.next;
|
|
227
219
|
newNode.prev = prevNode;
|
|
228
220
|
newNode.next = nextNode;
|
|
229
221
|
prevNode.next = newNode;
|
|
230
222
|
nextNode.prev = newNode;
|
|
231
223
|
this._length++;
|
|
232
224
|
return true;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
* The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
|
|
236
|
-
* @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
|
|
237
|
-
* data structure. It is of type number.
|
|
238
|
-
* @returns The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of
|
|
239
|
-
* bounds.
|
|
240
|
-
*/
|
|
241
|
-
deleteAt(index) {
|
|
225
|
+
};
|
|
226
|
+
DoublyLinkedList.prototype.deleteAt = function (index) {
|
|
242
227
|
if (index < 0 || index >= this.length)
|
|
243
|
-
return
|
|
228
|
+
return undefined;
|
|
244
229
|
if (index === 0)
|
|
245
230
|
return this.shift();
|
|
246
231
|
if (index === this.length - 1)
|
|
247
232
|
return this.pop();
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
233
|
+
var removedNode = this.getNodeAt(index);
|
|
234
|
+
var prevNode = removedNode.prev;
|
|
235
|
+
var nextNode = removedNode.next;
|
|
251
236
|
prevNode.next = nextNode;
|
|
252
237
|
nextNode.prev = prevNode;
|
|
253
238
|
this._length--;
|
|
254
239
|
return removedNode.val;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
* @param {T | DoublyLinkedListNode<T>} valOrNode - The `valOrNode` parameter can accept either a value of type `T` or
|
|
259
|
-
* a `DoublyLinkedListNode<T>` object.
|
|
260
|
-
* @returns The `delete` method returns a boolean value. It returns `true` if the value or node was successfully
|
|
261
|
-
* deleted from the doubly linked list, and `false` if the value or node was not found in the list.
|
|
262
|
-
*/
|
|
263
|
-
delete(valOrNode) {
|
|
264
|
-
let node;
|
|
240
|
+
};
|
|
241
|
+
DoublyLinkedList.prototype.delete = function (valOrNode) {
|
|
242
|
+
var node;
|
|
265
243
|
if (valOrNode instanceof DoublyLinkedListNode) {
|
|
266
244
|
node = valOrNode;
|
|
267
245
|
}
|
|
@@ -276,8 +254,8 @@ class DoublyLinkedList {
|
|
|
276
254
|
this.pop();
|
|
277
255
|
}
|
|
278
256
|
else {
|
|
279
|
-
|
|
280
|
-
|
|
257
|
+
var prevNode = node.prev;
|
|
258
|
+
var nextNode = node.next;
|
|
281
259
|
prevNode.next = nextNode;
|
|
282
260
|
nextNode.prev = prevNode;
|
|
283
261
|
this._length--;
|
|
@@ -285,37 +263,23 @@ class DoublyLinkedList {
|
|
|
285
263
|
return true;
|
|
286
264
|
}
|
|
287
265
|
return false;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
*/
|
|
293
|
-
toArray() {
|
|
294
|
-
const array = [];
|
|
295
|
-
let current = this.head;
|
|
266
|
+
};
|
|
267
|
+
DoublyLinkedList.prototype.toArray = function () {
|
|
268
|
+
var array = [];
|
|
269
|
+
var current = this.head;
|
|
296
270
|
while (current) {
|
|
297
271
|
array.push(current.val);
|
|
298
272
|
current = current.next;
|
|
299
273
|
}
|
|
300
274
|
return array;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
* The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively.
|
|
304
|
-
*/
|
|
305
|
-
clear() {
|
|
275
|
+
};
|
|
276
|
+
DoublyLinkedList.prototype.clear = function () {
|
|
306
277
|
this._head = null;
|
|
307
278
|
this._tail = null;
|
|
308
279
|
this._length = 0;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
* @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This
|
|
313
|
-
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
|
|
314
|
-
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
|
|
315
|
-
* the callback function. If no element satisfies the condition, it returns `null`.
|
|
316
|
-
*/
|
|
317
|
-
find(callback) {
|
|
318
|
-
let current = this.head;
|
|
280
|
+
};
|
|
281
|
+
DoublyLinkedList.prototype.find = function (callback) {
|
|
282
|
+
var current = this.head;
|
|
319
283
|
while (current) {
|
|
320
284
|
if (callback(current.val)) {
|
|
321
285
|
return current.val;
|
|
@@ -323,17 +287,10 @@ class DoublyLinkedList {
|
|
|
323
287
|
current = current.next;
|
|
324
288
|
}
|
|
325
289
|
return null;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
* that we are searching for in the linked list.
|
|
331
|
-
* @returns The method `indexOf` returns the index of the first occurrence of the specified value `val` in the linked
|
|
332
|
-
* list. If the value is not found, it returns -1.
|
|
333
|
-
*/
|
|
334
|
-
indexOf(val) {
|
|
335
|
-
let index = 0;
|
|
336
|
-
let current = this.head;
|
|
290
|
+
};
|
|
291
|
+
DoublyLinkedList.prototype.indexOf = function (val) {
|
|
292
|
+
var index = 0;
|
|
293
|
+
var current = this.head;
|
|
337
294
|
while (current) {
|
|
338
295
|
if (current.val === val) {
|
|
339
296
|
return index;
|
|
@@ -342,17 +299,9 @@ class DoublyLinkedList {
|
|
|
342
299
|
current = current.next;
|
|
343
300
|
}
|
|
344
301
|
return -1;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
* value that satisfies the given callback function, or null if no value satisfies the callback.
|
|
349
|
-
* @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This
|
|
350
|
-
* function is used to determine whether a given value satisfies a certain condition.
|
|
351
|
-
* @returns The method `findLast` returns the last value in the linked list that satisfies the condition specified by
|
|
352
|
-
* the callback function. If no value satisfies the condition, it returns `null`.
|
|
353
|
-
*/
|
|
354
|
-
findLast(callback) {
|
|
355
|
-
let current = this.tail;
|
|
302
|
+
};
|
|
303
|
+
DoublyLinkedList.prototype.findLast = function (callback) {
|
|
304
|
+
var current = this.tail;
|
|
356
305
|
while (current) {
|
|
357
306
|
if (callback(current.val)) {
|
|
358
307
|
return current.val;
|
|
@@ -360,74 +309,47 @@ class DoublyLinkedList {
|
|
|
360
309
|
current = current.prev;
|
|
361
310
|
}
|
|
362
311
|
return null;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
*/
|
|
368
|
-
toArrayReverse() {
|
|
369
|
-
const array = [];
|
|
370
|
-
let current = this.tail;
|
|
312
|
+
};
|
|
313
|
+
DoublyLinkedList.prototype.toArrayReverse = function () {
|
|
314
|
+
var array = [];
|
|
315
|
+
var current = this.tail;
|
|
371
316
|
while (current) {
|
|
372
317
|
array.push(current.val);
|
|
373
318
|
current = current.prev;
|
|
374
319
|
}
|
|
375
320
|
return array;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
let current = this.head;
|
|
382
|
-
[this.head, this.tail] = [this.tail, this.head];
|
|
321
|
+
};
|
|
322
|
+
DoublyLinkedList.prototype.reverse = function () {
|
|
323
|
+
var _a, _b;
|
|
324
|
+
var current = this.head;
|
|
325
|
+
_a = __read([this.tail, this.head], 2), this.head = _a[0], this.tail = _a[1];
|
|
383
326
|
while (current) {
|
|
384
|
-
|
|
385
|
-
[current.
|
|
327
|
+
var next = current.next;
|
|
328
|
+
_b = __read([current.next, current.prev], 2), current.prev = _b[0], current.next = _b[1];
|
|
386
329
|
current = next;
|
|
387
330
|
}
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
* represents the value of the current node in the linked list, and the index argument represents the index of the
|
|
393
|
-
* current node in the linked list.
|
|
394
|
-
*/
|
|
395
|
-
forEach(callback) {
|
|
396
|
-
let current = this.head;
|
|
397
|
-
let index = 0;
|
|
331
|
+
};
|
|
332
|
+
DoublyLinkedList.prototype.forEach = function (callback) {
|
|
333
|
+
var current = this.head;
|
|
334
|
+
var index = 0;
|
|
398
335
|
while (current) {
|
|
399
336
|
callback(current.val, index);
|
|
400
337
|
current = current.next;
|
|
401
338
|
index++;
|
|
402
339
|
}
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
* @param callback - The callback parameter is a function that takes a value of type T (the type of values stored in
|
|
408
|
-
* the original DoublyLinkedList) and returns a value of type U (the type of values that will be stored in the mapped
|
|
409
|
-
* DoublyLinkedList).
|
|
410
|
-
* @returns The `map` function is returning a new instance of `DoublyLinkedList<U>` that contains the mapped values.
|
|
411
|
-
*/
|
|
412
|
-
map(callback) {
|
|
413
|
-
const mappedList = new DoublyLinkedList();
|
|
414
|
-
let current = this.head;
|
|
340
|
+
};
|
|
341
|
+
DoublyLinkedList.prototype.map = function (callback) {
|
|
342
|
+
var mappedList = new DoublyLinkedList();
|
|
343
|
+
var current = this.head;
|
|
415
344
|
while (current) {
|
|
416
345
|
mappedList.push(callback(current.val));
|
|
417
346
|
current = current.next;
|
|
418
347
|
}
|
|
419
348
|
return mappedList;
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
* @param callback - The `callback` parameter is a function that takes a value of type `T` and returns a boolean value.
|
|
425
|
-
* It is used to determine whether a value should be included in the filtered list or not.
|
|
426
|
-
* @returns The filtered list, which is an instance of the DoublyLinkedList class.
|
|
427
|
-
*/
|
|
428
|
-
filter(callback) {
|
|
429
|
-
const filteredList = new DoublyLinkedList();
|
|
430
|
-
let current = this.head;
|
|
349
|
+
};
|
|
350
|
+
DoublyLinkedList.prototype.filter = function (callback) {
|
|
351
|
+
var filteredList = new DoublyLinkedList();
|
|
352
|
+
var current = this.head;
|
|
431
353
|
while (current) {
|
|
432
354
|
if (callback(current.val)) {
|
|
433
355
|
filteredList.push(current.val);
|
|
@@ -435,37 +357,18 @@ class DoublyLinkedList {
|
|
|
435
357
|
current = current.next;
|
|
436
358
|
}
|
|
437
359
|
return filteredList;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
* @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `val`. It is
|
|
443
|
-
* used to perform a specific operation on each element of the linked list.
|
|
444
|
-
* @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
|
|
445
|
-
* point for the reduction operation.
|
|
446
|
-
* @returns The `reduce` method is returning the final value of the accumulator after iterating through all the
|
|
447
|
-
* elements in the linked list.
|
|
448
|
-
*/
|
|
449
|
-
reduce(callback, initialValue) {
|
|
450
|
-
let accumulator = initialValue;
|
|
451
|
-
let current = this.head;
|
|
360
|
+
};
|
|
361
|
+
DoublyLinkedList.prototype.reduce = function (callback, initialValue) {
|
|
362
|
+
var accumulator = initialValue;
|
|
363
|
+
var current = this.head;
|
|
452
364
|
while (current) {
|
|
453
365
|
accumulator = callback(accumulator, current.val);
|
|
454
366
|
current = current.next;
|
|
455
367
|
}
|
|
456
368
|
return accumulator;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
* @param {T | DoublyLinkedListNode<T>} existingValueOrNode - The existing value or node in the doubly linked list
|
|
461
|
-
* after which the new value will be inserted. It can be either the value of the existing node or the existing node
|
|
462
|
-
* itself.
|
|
463
|
-
* @param {T} newValue - The value that you want to insert into the doubly linked list.
|
|
464
|
-
* @returns The method returns a boolean value. It returns true if the insertion is successful, and false if the
|
|
465
|
-
* existing value or node is not found in the doubly linked list.
|
|
466
|
-
*/
|
|
467
|
-
insertAfter(existingValueOrNode, newValue) {
|
|
468
|
-
let existingNode;
|
|
369
|
+
};
|
|
370
|
+
DoublyLinkedList.prototype.insertAfter = function (existingValueOrNode, newValue) {
|
|
371
|
+
var existingNode;
|
|
469
372
|
if (existingValueOrNode instanceof DoublyLinkedListNode) {
|
|
470
373
|
existingNode = existingValueOrNode;
|
|
471
374
|
}
|
|
@@ -473,7 +376,7 @@ class DoublyLinkedList {
|
|
|
473
376
|
existingNode = this.findNode(existingValueOrNode);
|
|
474
377
|
}
|
|
475
378
|
if (existingNode) {
|
|
476
|
-
|
|
379
|
+
var newNode = new DoublyLinkedListNode(newValue);
|
|
477
380
|
newNode.next = existingNode.next;
|
|
478
381
|
if (existingNode.next) {
|
|
479
382
|
existingNode.next.prev = newNode;
|
|
@@ -487,19 +390,9 @@ class DoublyLinkedList {
|
|
|
487
390
|
return true;
|
|
488
391
|
}
|
|
489
392
|
return false;
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
* @param {T | DoublyLinkedListNode<T>} existingValueOrNode - The existing value or node in the doubly linked list
|
|
494
|
-
* before which the new value will be inserted. It can be either the value of the existing node or the existing node
|
|
495
|
-
* itself.
|
|
496
|
-
* @param {T} newValue - The `newValue` parameter represents the value that you want to insert into the doubly linked
|
|
497
|
-
* list.
|
|
498
|
-
* @returns The method returns a boolean value. It returns `true` if the insertion is successful, and `false` if the
|
|
499
|
-
* insertion fails.
|
|
500
|
-
*/
|
|
501
|
-
insertBefore(existingValueOrNode, newValue) {
|
|
502
|
-
let existingNode;
|
|
393
|
+
};
|
|
394
|
+
DoublyLinkedList.prototype.insertBefore = function (existingValueOrNode, newValue) {
|
|
395
|
+
var existingNode;
|
|
503
396
|
if (existingValueOrNode instanceof DoublyLinkedListNode) {
|
|
504
397
|
existingNode = existingValueOrNode;
|
|
505
398
|
}
|
|
@@ -507,7 +400,7 @@ class DoublyLinkedList {
|
|
|
507
400
|
existingNode = this.findNode(existingValueOrNode);
|
|
508
401
|
}
|
|
509
402
|
if (existingNode) {
|
|
510
|
-
|
|
403
|
+
var newNode = new DoublyLinkedListNode(newValue);
|
|
511
404
|
newNode.prev = existingNode.prev;
|
|
512
405
|
if (existingNode.prev) {
|
|
513
406
|
existingNode.prev.next = newNode;
|
|
@@ -521,6 +414,8 @@ class DoublyLinkedList {
|
|
|
521
414
|
return true;
|
|
522
415
|
}
|
|
523
416
|
return false;
|
|
524
|
-
}
|
|
525
|
-
|
|
417
|
+
};
|
|
418
|
+
return DoublyLinkedList;
|
|
419
|
+
}());
|
|
526
420
|
exports.DoublyLinkedList = DoublyLinkedList;
|
|
421
|
+
//# sourceMappingURL=doubly-linked-list.js.map
|