data-structure-typed 0.9.16 → 1.3.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/LICENSE +21 -0
- package/README.md +665 -172
- package/dist/bundle.js +2 -0
- package/dist/bundle.js.LICENSE.txt +13 -0
- package/dist/data-structures/binary-tree/aa-tree.js +2 -5
- package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +364 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +1308 -0
- package/dist/data-structures/binary-tree/avl-tree.d.ts +85 -14
- package/dist/data-structures/binary-tree/avl-tree.js +142 -116
- package/dist/data-structures/binary-tree/b-tree.js +2 -5
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +39 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +54 -13
- package/dist/data-structures/binary-tree/binary-tree.d.ts +29 -126
- package/dist/data-structures/binary-tree/binary-tree.js +31 -1093
- package/dist/data-structures/binary-tree/bst.d.ts +117 -23
- package/dist/data-structures/binary-tree/bst.js +233 -240
- package/dist/data-structures/binary-tree/index.d.ts +1 -0
- package/dist/data-structures/binary-tree/index.js +1 -0
- package/dist/data-structures/binary-tree/rb-tree.d.ts +18 -1
- package/dist/data-structures/binary-tree/rb-tree.js +40 -5
- package/dist/data-structures/binary-tree/segment-tree.d.ts +61 -11
- package/dist/data-structures/binary-tree/segment-tree.js +126 -93
- package/dist/data-structures/binary-tree/splay-tree.js +2 -5
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +213 -6
- package/dist/data-structures/binary-tree/tree-multiset.js +687 -34
- package/dist/data-structures/binary-tree/two-three-tree.js +2 -5
- package/dist/data-structures/graph/abstract-graph.d.ts +270 -36
- package/dist/data-structures/graph/abstract-graph.js +610 -572
- package/dist/data-structures/graph/directed-graph.d.ts +173 -16
- package/dist/data-structures/graph/directed-graph.js +345 -313
- package/dist/data-structures/graph/index.d.ts +1 -0
- package/dist/data-structures/graph/index.js +1 -0
- package/dist/data-structures/graph/map-graph.d.ts +79 -0
- package/dist/data-structures/graph/map-graph.js +111 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +111 -9
- package/dist/data-structures/graph/undirected-graph.js +203 -178
- package/dist/data-structures/hash/coordinate-map.d.ts +38 -1
- package/dist/data-structures/hash/coordinate-map.js +59 -36
- package/dist/data-structures/hash/coordinate-set.d.ts +32 -2
- package/dist/data-structures/hash/coordinate-set.js +49 -33
- package/dist/data-structures/hash/hash-table.d.ts +2 -1
- package/dist/data-structures/hash/hash-table.js +4 -0
- package/dist/data-structures/hash/pair.d.ts +2 -1
- package/dist/data-structures/hash/pair.js +4 -0
- package/dist/data-structures/hash/tree-map.d.ts +2 -1
- package/dist/data-structures/hash/tree-map.js +4 -0
- package/dist/data-structures/hash/tree-set.d.ts +2 -1
- package/dist/data-structures/hash/tree-set.js +4 -0
- package/dist/data-structures/heap/heap.d.ts +62 -45
- package/dist/data-structures/heap/heap.js +124 -86
- package/dist/data-structures/heap/max-heap.d.ts +13 -5
- package/dist/data-structures/heap/max-heap.js +18 -28
- package/dist/data-structures/heap/min-heap.d.ts +14 -5
- package/dist/data-structures/heap/min-heap.js +19 -28
- package/dist/data-structures/index.d.ts +1 -1
- package/dist/data-structures/index.js +1 -1
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +193 -56
- package/dist/data-structures/linked-list/doubly-linked-list.js +484 -220
- package/dist/data-structures/linked-list/index.d.ts +1 -0
- package/dist/data-structures/linked-list/index.js +1 -0
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +117 -315
- package/dist/data-structures/linked-list/singly-linked-list.js +374 -727
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -1
- package/dist/data-structures/linked-list/skip-linked-list.js +4 -0
- package/dist/data-structures/matrix/matrix.d.ts +12 -0
- package/dist/data-structures/matrix/matrix.js +21 -8
- package/dist/data-structures/matrix/matrix2d.d.ts +85 -2
- package/dist/data-structures/matrix/matrix2d.js +146 -80
- package/dist/data-structures/matrix/navigator.d.ts +36 -1
- package/dist/data-structures/matrix/navigator.js +46 -37
- package/dist/data-structures/matrix/vector2d.d.ts +142 -15
- package/dist/data-structures/matrix/vector2d.js +215 -109
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -2
- package/dist/data-structures/priority-queue/max-priority-queue.js +33 -26
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +12 -2
- package/dist/data-structures/priority-queue/min-priority-queue.js +34 -26
- package/dist/data-structures/priority-queue/priority-queue.d.ts +153 -3
- package/dist/data-structures/priority-queue/priority-queue.js +244 -143
- package/dist/data-structures/queue/deque.d.ts +141 -13
- package/dist/data-structures/queue/deque.js +200 -82
- package/dist/data-structures/queue/queue.d.ts +65 -38
- package/dist/data-structures/queue/queue.js +110 -66
- package/dist/data-structures/stack/stack.d.ts +27 -32
- package/dist/data-structures/stack/stack.js +47 -53
- package/dist/data-structures/tree/index.d.ts +1 -0
- package/dist/data-structures/tree/index.js +17 -0
- package/dist/data-structures/tree/tree.d.ts +14 -0
- package/dist/data-structures/tree/tree.js +60 -0
- package/dist/data-structures/trie/trie.d.ts +33 -10
- package/dist/data-structures/trie/trie.js +123 -208
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/interfaces/abstract-binary-tree.d.ts +90 -0
- package/dist/interfaces/abstract-graph.d.ts +17 -0
- package/dist/interfaces/avl-tree.d.ts +9 -0
- package/dist/interfaces/binary-tree.d.ts +6 -0
- package/dist/interfaces/bst.d.ts +17 -0
- package/dist/interfaces/directed-graph.d.ts +12 -0
- package/{src/data-structures/types/index.ts → dist/interfaces/index.d.ts} +10 -8
- package/dist/interfaces/index.js +31 -0
- package/{src/data-structures/hash/hash-table.ts → dist/interfaces/priority-queue.d.ts} +1 -1
- package/dist/interfaces/rb-tree.d.ts +8 -0
- package/dist/interfaces/segment-tree.d.ts +1 -0
- package/dist/interfaces/singly-linked-list.d.ts +1 -0
- package/dist/interfaces/singly-linked-list.js +2 -0
- package/dist/interfaces/tree-multiset.d.ts +7 -0
- package/dist/interfaces/tree-multiset.js +2 -0
- package/dist/interfaces/undirected-graph.d.ts +5 -0
- package/dist/interfaces/undirected-graph.js +2 -0
- package/dist/types/data-structures/abstract-binary-tree.d.ts +34 -0
- package/dist/types/data-structures/abstract-binary-tree.js +25 -0
- package/dist/types/data-structures/abstract-graph.d.ts +11 -0
- package/dist/types/data-structures/abstract-graph.js +2 -0
- package/dist/types/data-structures/avl-tree.d.ts +4 -0
- package/dist/types/data-structures/avl-tree.js +2 -0
- package/dist/types/data-structures/binary-tree.d.ts +4 -0
- package/dist/types/data-structures/binary-tree.js +2 -0
- package/dist/types/data-structures/bst.d.ts +13 -0
- package/dist/types/data-structures/bst.js +9 -0
- package/dist/types/data-structures/directed-graph.d.ts +6 -0
- package/dist/types/data-structures/directed-graph.js +9 -0
- package/dist/types/data-structures/doubly-linked-list.d.ts +1 -0
- package/dist/types/data-structures/doubly-linked-list.js +2 -0
- package/dist/types/data-structures/heap.d.ts +3 -0
- package/dist/types/data-structures/heap.js +2 -0
- package/dist/{data-structures/types → types/data-structures}/index.d.ts +3 -1
- package/dist/{data-structures/types → types/data-structures}/index.js +3 -1
- package/dist/types/data-structures/map-graph.d.ts +1 -0
- package/dist/types/data-structures/map-graph.js +2 -0
- package/dist/{data-structures/types → types/data-structures}/navigator.d.ts +2 -2
- package/dist/types/data-structures/navigator.js +2 -0
- package/dist/{data-structures/types → types/data-structures}/priority-queue.d.ts +2 -2
- package/dist/types/data-structures/priority-queue.js +2 -0
- package/dist/types/data-structures/rb-tree.d.ts +8 -0
- package/dist/types/data-structures/rb-tree.js +8 -0
- package/dist/types/data-structures/segment-tree.js +2 -0
- package/dist/types/data-structures/singly-linked-list.d.ts +1 -0
- package/dist/types/data-structures/singly-linked-list.js +2 -0
- package/dist/types/data-structures/tree-multiset.d.ts +4 -0
- package/dist/types/data-structures/tree-multiset.js +2 -0
- package/dist/types/helpers.d.ts +1 -0
- package/dist/types/helpers.js +2 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +19 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/index.js +18 -0
- package/dist/types/utils/utils.d.ts +7 -0
- package/dist/types/utils/utils.js +2 -0
- package/dist/types/utils/validate-type.d.ts +19 -0
- package/dist/types/utils/validate-type.js +2 -0
- package/dist/utils/utils.d.ts +17 -103
- package/dist/utils/utils.js +40 -625
- package/package.json +96 -23
- package/.idea/data-structure-typed.iml +0 -12
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/dist/data-structures/trampoline.d.ts +0 -16
- package/dist/data-structures/trampoline.js +0 -130
- package/dist/data-structures/types/abstract-graph.d.ts +0 -29
- package/dist/data-structures/types/avl-tree.d.ts +0 -5
- package/dist/data-structures/types/binary-tree.d.ts +0 -16
- package/dist/data-structures/types/bst.d.ts +0 -7
- package/dist/data-structures/types/directed-graph.d.ts +0 -10
- package/dist/data-structures/types/doubly-linked-list.d.ts +0 -1
- package/dist/data-structures/types/heap.d.ts +0 -7
- package/dist/data-structures/types/singly-linked-list.d.ts +0 -5
- package/dist/data-structures/types/tree-multiset.d.ts +0 -5
- package/dist/data-structures/types/utils.d.ts +0 -52
- package/dist/data-structures/types/utils.js +0 -54
- package/src/data-structures/binary-tree/aa-tree.ts +0 -3
- package/src/data-structures/binary-tree/avl-tree.ts +0 -227
- package/src/data-structures/binary-tree/b-tree.ts +0 -3
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -33
- package/src/data-structures/binary-tree/binary-tree.ts +0 -1133
- package/src/data-structures/binary-tree/bst.ts +0 -395
- package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
- package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
- package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
- package/src/data-structures/binary-tree/index.ts +0 -11
- package/src/data-structures/binary-tree/rb-tree.ts +0 -3
- package/src/data-structures/binary-tree/segment-tree.ts +0 -172
- package/src/data-structures/binary-tree/splay-tree.ts +0 -3
- package/src/data-structures/binary-tree/tree-multiset.ts +0 -18
- package/src/data-structures/binary-tree/two-three-tree.ts +0 -3
- package/src/data-structures/diagrams/README.md +0 -7
- package/src/data-structures/graph/abstract-graph.ts +0 -753
- package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-list.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix.png +0 -0
- package/src/data-structures/graph/diagrams/dfs-can-do.png +0 -0
- package/src/data-structures/graph/diagrams/edge-list-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/edge-list.png +0 -0
- package/src/data-structures/graph/diagrams/max-flow.png +0 -0
- package/src/data-structures/graph/diagrams/mst.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
- package/src/data-structures/graph/directed-graph.ts +0 -306
- package/src/data-structures/graph/index.ts +0 -3
- package/src/data-structures/graph/undirected-graph.ts +0 -155
- package/src/data-structures/hash/coordinate-map.ts +0 -24
- package/src/data-structures/hash/coordinate-set.ts +0 -20
- package/src/data-structures/hash/index.ts +0 -6
- package/src/data-structures/heap/heap.ts +0 -127
- package/src/data-structures/heap/index.ts +0 -3
- package/src/data-structures/heap/max-heap.ts +0 -23
- package/src/data-structures/heap/min-heap.ts +0 -25
- package/src/data-structures/index.ts +0 -12
- package/src/data-structures/linked-list/doubly-linked-list.ts +0 -250
- package/src/data-structures/linked-list/index.ts +0 -2
- package/src/data-structures/linked-list/singly-linked-list.ts +0 -736
- package/src/data-structures/linked-list/skip-linked-list.ts +0 -1
- package/src/data-structures/matrix/index.ts +0 -4
- package/src/data-structures/matrix/matrix.ts +0 -13
- package/src/data-structures/matrix/matrix2d.ts +0 -125
- package/src/data-structures/matrix/navigator.ts +0 -87
- package/src/data-structures/matrix/vector2d.ts +0 -189
- package/src/data-structures/priority-queue/index.ts +0 -3
- package/src/data-structures/priority-queue/max-priority-queue.ts +0 -13
- package/src/data-structures/priority-queue/min-priority-queue.ts +0 -13
- package/src/data-structures/priority-queue/priority-queue.ts +0 -200
- package/src/data-structures/queue/deque.ts +0 -139
- package/src/data-structures/queue/index.ts +0 -2
- package/src/data-structures/queue/queue.ts +0 -122
- package/src/data-structures/stack/index.ts +0 -1
- package/src/data-structures/stack/stack.ts +0 -103
- package/src/data-structures/trampoline.ts +0 -51
- package/src/data-structures/trie/index.ts +0 -1
- package/src/data-structures/trie/trie.ts +0 -203
- package/src/data-structures/types/abstract-graph.ts +0 -51
- package/src/data-structures/types/avl-tree.ts +0 -6
- package/src/data-structures/types/binary-tree.ts +0 -15
- package/src/data-structures/types/bst.ts +0 -5
- package/src/data-structures/types/directed-graph.ts +0 -18
- package/src/data-structures/types/doubly-linked-list.ts +0 -1
- package/src/data-structures/types/heap.ts +0 -8
- package/src/data-structures/types/navigator.ts +0 -12
- package/src/data-structures/types/priority-queue.ts +0 -9
- package/src/data-structures/types/segment-tree.ts +0 -1
- package/src/data-structures/types/singly-linked-list.ts +0 -15
- package/src/data-structures/types/tree-multiset.ts +0 -3
- package/src/data-structures/types/utils.ts +0 -173
- package/src/index.ts +0 -1
- package/src/utils/index.ts +0 -1
- package/src/utils/utils.ts +0 -505
- package/tsconfig.json +0 -56
- /package/dist/{data-structures/types/abstract-graph.js → interfaces/abstract-binary-tree.js} +0 -0
- /package/dist/{data-structures/types/avl-tree.js → interfaces/abstract-graph.js} +0 -0
- /package/dist/{data-structures/types/binary-tree.js → interfaces/avl-tree.js} +0 -0
- /package/dist/{data-structures/types/bst.js → interfaces/binary-tree.js} +0 -0
- /package/dist/{data-structures/types/directed-graph.js → interfaces/bst.js} +0 -0
- /package/dist/{data-structures/types/doubly-linked-list.js → interfaces/directed-graph.js} +0 -0
- /package/{src/data-structures/hash/pair.ts → dist/interfaces/doubly-linked-list.d.ts} +0 -0
- /package/dist/{data-structures/types/heap.js → interfaces/doubly-linked-list.js} +0 -0
- /package/{src/data-structures/hash/tree-map.ts → dist/interfaces/heap.d.ts} +0 -0
- /package/dist/{data-structures/types/navigator.js → interfaces/heap.js} +0 -0
- /package/{src/data-structures/hash/tree-set.ts → dist/interfaces/navigator.d.ts} +0 -0
- /package/dist/{data-structures/types/priority-queue.js → interfaces/navigator.js} +0 -0
- /package/dist/{data-structures/types/segment-tree.js → interfaces/priority-queue.js} +0 -0
- /package/dist/{data-structures/types/singly-linked-list.js → interfaces/rb-tree.js} +0 -0
- /package/dist/{data-structures/types/tree-multiset.js → interfaces/segment-tree.js} +0 -0
- /package/dist/{data-structures/types → types/data-structures}/segment-tree.d.ts +0 -0
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./singly-linked-list"), exports);
|
|
18
18
|
__exportStar(require("./doubly-linked-list"), exports);
|
|
19
|
+
__exportStar(require("./skip-linked-list"), exports);
|
|
@@ -1,354 +1,156 @@
|
|
|
1
|
-
import type { TMapFunction, TTestFunction } from '../types';
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
export declare class SinglyLinkedListNode<
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
prev: SinglyLinkedListNode<NodeData> | null,
|
|
22
|
-
/** The next link in the list */
|
|
23
|
-
next: SinglyLinkedListNode<NodeData> | null,
|
|
24
|
-
/** The list this node belongs to */
|
|
25
|
-
list: SinglyLinkedList<NodeData> | null);
|
|
26
|
-
/**
|
|
27
|
-
* Alias to .val
|
|
28
|
-
* ```ts
|
|
29
|
-
* new LinkedList(1, 2, 3).head.value; // 1
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
get value(): NodeData;
|
|
33
|
-
/**
|
|
34
|
-
* Get the index of this node
|
|
35
|
-
* ```ts
|
|
36
|
-
* new LinkedList(1, 2, 3).head.index; // 0
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
get index(): number | undefined;
|
|
40
|
-
/**
|
|
41
|
-
* Insert a new node before this one
|
|
42
|
-
* ```ts
|
|
43
|
-
* new LinkedList(2, 3).head.insertBefore(1); // 1 <=> 2 <=> 3
|
|
44
|
-
* ```
|
|
45
|
-
* @param val Data to save in the node
|
|
46
|
-
*/
|
|
47
|
-
insertBefore(val: NodeData): SinglyLinkedList<NodeData>;
|
|
48
|
-
/**
|
|
49
|
-
* Insert new val after this node
|
|
50
|
-
* ```ts
|
|
51
|
-
* new LinkedList(1, 2).tail.insertAfter(3); // 1 <=> 2 <=> 3
|
|
52
|
-
* ```
|
|
53
|
-
* @param val Data to be saved in the node
|
|
54
|
-
*/
|
|
55
|
-
insertAfter(val: NodeData): SinglyLinkedList<NodeData>;
|
|
56
|
-
/**
|
|
57
|
-
* Remove this node
|
|
58
|
-
* ```ts
|
|
59
|
-
* new LinkedList(1, 2, 3, 4).tail.remove(); // 1 <=> 2 <=> 3
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
remove(): SinglyLinkedListNode<NodeData>;
|
|
8
|
+
export declare class SinglyLinkedListNode<T = number> {
|
|
9
|
+
/**
|
|
10
|
+
* The constructor function initializes an instance of a class with a given value and sets the next property to null.
|
|
11
|
+
* @param {T} val - The "val" parameter is of type T, which means it can be any data type. It represents the value that
|
|
12
|
+
* will be stored in the node of a linked list.
|
|
13
|
+
*/
|
|
14
|
+
constructor(val: T);
|
|
15
|
+
private _val;
|
|
16
|
+
get val(): T;
|
|
17
|
+
set val(value: T);
|
|
18
|
+
private _next;
|
|
19
|
+
get next(): SinglyLinkedListNode<T> | null;
|
|
20
|
+
set next(value: SinglyLinkedListNode<T> | null);
|
|
63
21
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
/** Internal size reference */
|
|
77
|
-
private size;
|
|
78
|
-
constructor(...args: NodeData[]);
|
|
79
|
-
/**
|
|
80
|
-
* The length of the list
|
|
81
|
-
*/
|
|
22
|
+
export declare class SinglyLinkedList<T = any> {
|
|
23
|
+
/**
|
|
24
|
+
* The constructor initializes the linked list with an empty head, tail, and length.
|
|
25
|
+
*/
|
|
26
|
+
constructor();
|
|
27
|
+
private _head;
|
|
28
|
+
get head(): SinglyLinkedListNode<T> | null;
|
|
29
|
+
set head(value: SinglyLinkedListNode<T> | null);
|
|
30
|
+
private _tail;
|
|
31
|
+
get tail(): SinglyLinkedListNode<T> | null;
|
|
32
|
+
set tail(value: SinglyLinkedListNode<T> | null);
|
|
33
|
+
private _length;
|
|
82
34
|
get length(): number;
|
|
83
35
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* ```
|
|
89
|
-
* @param iterable Any iterable datatype like Array or Map
|
|
90
|
-
*/
|
|
91
|
-
static from<T>(iterable: Iterable<T>): SinglyLinkedList<T>;
|
|
92
|
-
/**
|
|
93
|
-
* Get the node val at a specified index, zero based
|
|
94
|
-
* ```ts
|
|
95
|
-
* new LinkedList(1, 2, 3).get(0); // 1
|
|
96
|
-
* ```
|
|
97
|
-
* @param index to retrieve val at
|
|
98
|
-
*/
|
|
99
|
-
get(index: number): NodeData | undefined;
|
|
100
|
-
/**
|
|
101
|
-
* Get the node at index, zero based
|
|
102
|
-
* ```ts
|
|
103
|
-
* new LinkedList(1, 2, 3).getNode(0);
|
|
104
|
-
* // { prev: null, val: 1, next: SinglyLinkedListNode }
|
|
105
|
-
* ```
|
|
106
|
-
*/
|
|
107
|
-
getNode(index: number): SinglyLinkedListNode<NodeData> | undefined;
|
|
108
|
-
/**
|
|
109
|
-
* Return the first node and its index in the list that
|
|
110
|
-
* satisfies the testing function
|
|
111
|
-
* ```ts
|
|
112
|
-
* new LinkedList(1, 2, 3).findNodeIndex(val => val === 1);
|
|
113
|
-
* // { node: SinglyLinkedListNode, index: 0 }
|
|
114
|
-
* ```
|
|
115
|
-
* @param f A function to be applied to the val of each node
|
|
116
|
-
*/
|
|
117
|
-
findNodeIndex(f: TTestFunction<NodeData>): ({
|
|
118
|
-
node: SinglyLinkedListNode<NodeData>;
|
|
119
|
-
index: number;
|
|
120
|
-
}) | undefined;
|
|
121
|
-
/**
|
|
122
|
-
* Returns the first node in the list that
|
|
123
|
-
* satisfies the provided testing function. Otherwise undefined is returned.
|
|
124
|
-
* ```ts
|
|
125
|
-
* new LinkedList(1, 2, 3).findNode(val => val === 1);
|
|
126
|
-
* // { prev: null, val: 1, next: SinglyLinkedListNode }
|
|
127
|
-
* ```
|
|
128
|
-
* @param f Function to test val against
|
|
129
|
-
*/
|
|
130
|
-
findNode(f: TTestFunction<NodeData>): SinglyLinkedListNode<NodeData> | undefined;
|
|
131
|
-
/**
|
|
132
|
-
* Returns the value of the first element in the list that
|
|
133
|
-
* satisfies the provided testing function. Otherwise undefined is returned.
|
|
134
|
-
* ```ts
|
|
135
|
-
* new LinkedList(1, 2, 3).find(val => val === 1); // 1
|
|
136
|
-
* ```
|
|
137
|
-
* @param f Function to test val against
|
|
138
|
-
*/
|
|
139
|
-
find(f: TTestFunction<NodeData>): NodeData | undefined;
|
|
140
|
-
/**
|
|
141
|
-
* Returns the index of the first node in the list that
|
|
142
|
-
* satisfies the provided testing function. Ohterwise -1 is returned.
|
|
143
|
-
* ```ts
|
|
144
|
-
* new LinkedList(1, 2, 3).findIndex(val => val === 3); // 2
|
|
145
|
-
* ```
|
|
146
|
-
* @param f Function to test val against
|
|
147
|
-
*/
|
|
148
|
-
findIndex(f: TTestFunction<NodeData>): number;
|
|
149
|
-
/**
|
|
150
|
-
* Append one or any number of nodes to the end of the list.
|
|
151
|
-
* This modifies the list in place and returns the list itself
|
|
152
|
-
* to make this method chainable.
|
|
153
|
-
* ```ts
|
|
154
|
-
* new LinkedList(1).append(2).append(3, 4); // 1 <=> 2 <=> 3 <=> 4
|
|
155
|
-
* ```
|
|
156
|
-
* @param args Data to be stored in the node, takes any number of arguments
|
|
157
|
-
*/
|
|
158
|
-
append(...args: NodeData[]): SinglyLinkedList<NodeData>;
|
|
159
|
-
/**
|
|
160
|
-
* Synonym for append
|
|
161
|
-
* ```ts
|
|
162
|
-
* new LinkedList(1).push(2).push(3, 4); // 1 <=> 2 <=> 3 <=> 4
|
|
163
|
-
* ```
|
|
164
|
-
* @param args Data to be stored, takes any number of arguments
|
|
165
|
-
*/
|
|
166
|
-
push(...args: NodeData[]): number;
|
|
167
|
-
/**
|
|
168
|
-
* Prepend any number of val arguments to the list. The
|
|
169
|
-
* argument list is prepended as a block to reduce confusion:
|
|
170
|
-
* ```javascript
|
|
171
|
-
* new LinkedList(3, 4).prepend(0, 1, 2); // [0, 1, 2, 3, 4]
|
|
172
|
-
* ```
|
|
173
|
-
* @param args Data to be stored in the node, accepts any number of arguments
|
|
174
|
-
*/
|
|
175
|
-
prepend(...args: NodeData[]): SinglyLinkedList<NodeData>;
|
|
176
|
-
/**
|
|
177
|
-
* Insert a new node at a given index position. If index is
|
|
178
|
-
* out of bounds, the node is appended, if index is negative
|
|
179
|
-
* or 0, it will be prepended.
|
|
180
|
-
* ```ts
|
|
181
|
-
* new LinkedList(1, 3).insertAt(1, 2); // 1 <=> 2 <=> 3
|
|
182
|
-
* ```
|
|
183
|
-
* @param index The index to insert the new node at
|
|
184
|
-
* @param val Data to be stored on the new node
|
|
185
|
-
*/
|
|
186
|
-
insertAt(index: number, val: NodeData): SinglyLinkedList<NodeData>;
|
|
187
|
-
/**
|
|
188
|
-
* Remove the specified node from the list and return the removed
|
|
189
|
-
* node afterwards.
|
|
190
|
-
* ```ts
|
|
191
|
-
* const list = new LinkedList(1, 2, 3);
|
|
192
|
-
* list.removeNode(list.tail); // { prev: null, val: 3, next: null, list: null }
|
|
193
|
-
* ```
|
|
194
|
-
* @param node The node to be removed
|
|
195
|
-
*/
|
|
196
|
-
removeNode(node: SinglyLinkedListNode<NodeData>): SinglyLinkedListNode<NodeData>;
|
|
197
|
-
/**
|
|
198
|
-
* Remove the node at the specified index
|
|
199
|
-
* ```ts
|
|
200
|
-
* new LinkedList(1, 2, 3).removeAt(2); // { prev: null, val: 3, next: null, list: null }
|
|
201
|
-
* ```
|
|
202
|
-
* @param index Index at which to remove
|
|
36
|
+
* The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
|
|
37
|
+
* array.
|
|
38
|
+
* @param {T[]} data - The `data` parameter is an array of elements of type `T`.
|
|
39
|
+
* @returns The `fromArray` function returns a `SinglyLinkedList` object.
|
|
203
40
|
*/
|
|
204
|
-
|
|
41
|
+
static fromArray<T>(data: T[]): SinglyLinkedList<T>;
|
|
42
|
+
getLength(): number;
|
|
205
43
|
/**
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
* list.insertBefore(list.tail, 2); // 1 <=> 2 <=> 3
|
|
210
|
-
* ```
|
|
211
|
-
* @param referenceNode The node reference
|
|
212
|
-
* @param val Data to save in the node
|
|
44
|
+
* The `push` function adds a new node with the given data to the end of a singly linked list.
|
|
45
|
+
* @param {T} data - The "data" parameter represents the value that you want to add to the linked list. It can be of
|
|
46
|
+
* any type (T) as specified in the generic type declaration of the class or function.
|
|
213
47
|
*/
|
|
214
|
-
|
|
48
|
+
push(data: T): void;
|
|
215
49
|
/**
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
* the sort order will be ascending.
|
|
50
|
+
* The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
|
|
51
|
+
* pointers accordingly.
|
|
52
|
+
* @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
|
|
53
|
+
* the linked list is empty, it returns `null`.
|
|
221
54
|
*/
|
|
222
|
-
|
|
55
|
+
pop(): T | undefined;
|
|
223
56
|
/**
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
* const list = new LinkedList(2, 3);
|
|
227
|
-
* list.insertAfter(list.head, 1); // 1 <=> 2 <=> 3
|
|
228
|
-
* ```
|
|
229
|
-
* @param referenceNode The reference node
|
|
230
|
-
* @param val Data to be saved in the node
|
|
57
|
+
* The `shift()` function removes and returns the value of the first node in a linked list.
|
|
58
|
+
* @returns The value of the node that is being removed from the beginning of the linked list.
|
|
231
59
|
*/
|
|
232
|
-
|
|
60
|
+
shift(): T | undefined;
|
|
233
61
|
/**
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
* new LinkedList(1, 2, 3).shift(); // 1
|
|
238
|
-
* ```
|
|
62
|
+
* The unshift function adds a new node with the given value to the beginning of a singly linked list.
|
|
63
|
+
* @param {T} val - The parameter "val" represents the value of the new node that will be added to the beginning of the
|
|
64
|
+
* linked list.
|
|
239
65
|
*/
|
|
240
|
-
|
|
66
|
+
unshift(val: T): void;
|
|
241
67
|
/**
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
68
|
+
* The function `getAt` returns the value at a specified index in a linked list, or null if the index is out of range.
|
|
69
|
+
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
70
|
+
* retrieve from the list.
|
|
71
|
+
* @returns The method `getAt(index: number): T | null` returns the value at the specified index in the linked list, or
|
|
72
|
+
* `null` if the index is out of bounds.
|
|
247
73
|
*/
|
|
248
|
-
|
|
74
|
+
getAt(index: number): T | null;
|
|
249
75
|
/**
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
* list.merge(otherList);
|
|
256
|
-
* (list === otherList); // true
|
|
257
|
-
* ```
|
|
258
|
-
* @param list The list to be merged
|
|
76
|
+
* The function `getNodeAt` returns the node at a given index in a singly linked list.
|
|
77
|
+
* @param {number} index - The `index` parameter is a number that represents the position of the node we want to
|
|
78
|
+
* retrieve from the linked list. It indicates the zero-based index of the node we want to access.
|
|
79
|
+
* @returns The method `getNodeAt(index: number)` returns a `SinglyLinkedListNode<T>` object if the node at the
|
|
80
|
+
* specified index exists, or `null` if the index is out of bounds.
|
|
259
81
|
*/
|
|
260
|
-
|
|
82
|
+
getNodeAt(index: number): SinglyLinkedListNode<T> | null;
|
|
261
83
|
/**
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
84
|
+
* The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
|
|
85
|
+
* @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
|
|
86
|
+
* data structure. It is of type number.
|
|
87
|
+
* @returns The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of
|
|
88
|
+
* bounds.
|
|
267
89
|
*/
|
|
268
|
-
|
|
90
|
+
deleteAt(index: number): T | undefined;
|
|
91
|
+
delete(valueOrNode: T): boolean;
|
|
92
|
+
delete(valueOrNode: SinglyLinkedListNode<T>): boolean;
|
|
269
93
|
/**
|
|
270
|
-
* The
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
* The
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
* ```
|
|
278
|
-
* @param start Start index
|
|
279
|
-
* @param end End index, optional
|
|
94
|
+
* The `insertAt` function inserts a value at a specified index in a singly linked list.
|
|
95
|
+
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
96
|
+
* linked list. It is of type number.
|
|
97
|
+
* @param {T} val - The `val` parameter represents the value that you want to insert into the linked list at the
|
|
98
|
+
* specified index.
|
|
99
|
+
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
|
|
100
|
+
* if the index is out of bounds.
|
|
280
101
|
*/
|
|
281
|
-
|
|
102
|
+
insertAt(index: number, val: T): boolean;
|
|
282
103
|
/**
|
|
283
|
-
* The
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
* new LinkedList(1, 2, 3).reverse(); // 3 <=> 2 <=> 1
|
|
287
|
-
* ```
|
|
104
|
+
* The function checks if the length of a data structure is equal to zero and returns a boolean value indicating
|
|
105
|
+
* whether it is empty or not.
|
|
106
|
+
* @returns A boolean value indicating whether the length of the object is equal to 0.
|
|
288
107
|
*/
|
|
289
|
-
|
|
108
|
+
isEmpty(): boolean;
|
|
290
109
|
/**
|
|
291
|
-
* The
|
|
292
|
-
* ```ts
|
|
293
|
-
* new LinkedList(1, 2, 3).forEach(val => log(val)); // 1 2 3
|
|
294
|
-
* ```
|
|
295
|
-
* @param f Function to execute for each element, taking up to three arguments.
|
|
296
|
-
* @param reverse Indicates if the list should be walked in reverse order, default is false
|
|
110
|
+
* The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively.
|
|
297
111
|
*/
|
|
298
|
-
|
|
112
|
+
clear(): void;
|
|
299
113
|
/**
|
|
300
|
-
* The
|
|
301
|
-
*
|
|
302
|
-
* ```ts
|
|
303
|
-
* new LinkedList(1, 2, 3).map(val => val + 10); // 11 <=> 12 <=> 13
|
|
304
|
-
* ```
|
|
305
|
-
* @param f Function that produces an node of the new list, taking up to three arguments
|
|
306
|
-
* @param reverse Indicates if the list should be mapped in reverse order, default is false
|
|
114
|
+
* The `toArray` function converts a linked list into an array.
|
|
115
|
+
* @returns The `toArray()` method is returning an array of type `T[]`.
|
|
307
116
|
*/
|
|
308
|
-
|
|
117
|
+
toArray(): T[];
|
|
309
118
|
/**
|
|
310
|
-
* The
|
|
311
|
-
*
|
|
312
|
-
* ```ts
|
|
313
|
-
* new LinkedList(1, 2, 3, 4, 5).filter(val => val < 4); // 1 <=> 2 <=> 3
|
|
314
|
-
* ```
|
|
315
|
-
* @param f Function to test each node val in the list. Return true to keep the node
|
|
316
|
-
* @param reverse Indicates if the list should be filtered in reverse order, default is false
|
|
119
|
+
* The `reverse` function reverses the order of the nodes in a singly linked list.
|
|
120
|
+
* @returns The reverse() method does not return anything. It has a return type of void.
|
|
317
121
|
*/
|
|
318
|
-
|
|
122
|
+
reverse(): void;
|
|
319
123
|
/**
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
* @param start An initial value
|
|
326
|
-
* @returns The final state of the accumulator
|
|
124
|
+
* The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
|
|
125
|
+
* @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This
|
|
126
|
+
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
|
|
127
|
+
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
|
|
128
|
+
* the callback function. If no element satisfies the condition, it returns `null`.
|
|
327
129
|
*/
|
|
328
|
-
|
|
130
|
+
find(callback: (val: T) => boolean): T | null;
|
|
329
131
|
/**
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
132
|
+
* The `indexOf` function returns the index of the first occurrence of a given value in a linked list.
|
|
133
|
+
* @param {T} value - The value parameter is the value that you want to find the index of in the linked list.
|
|
134
|
+
* @returns The method is returning the index of the first occurrence of the specified value in the linked list. If the
|
|
135
|
+
* value is not found, it returns -1.
|
|
334
136
|
*/
|
|
335
|
-
|
|
137
|
+
indexOf(value: T): number;
|
|
336
138
|
/**
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
*
|
|
139
|
+
* The function finds a node in a singly linked list by its value and returns the node if found, otherwise returns
|
|
140
|
+
* null.
|
|
141
|
+
* @param {T} value - The value parameter is the value that we want to search for in the linked list.
|
|
142
|
+
* @returns a `SinglyLinkedListNode<T>` if a node with the specified value is found in the linked list. If no node with
|
|
143
|
+
* the specified value is found, the function returns `null`.
|
|
342
144
|
*/
|
|
343
|
-
|
|
145
|
+
findNode(value: T): SinglyLinkedListNode<T> | null;
|
|
146
|
+
insertBefore(existingValue: T, newValue: T): boolean;
|
|
147
|
+
insertBefore(existingValue: SinglyLinkedListNode<T>, newValue: T): boolean;
|
|
148
|
+
insertAfter(existingValueOrNode: T, newValue: T): boolean;
|
|
149
|
+
insertAfter(existingValueOrNode: SinglyLinkedListNode<T>, newValue: T): boolean;
|
|
344
150
|
/**
|
|
345
|
-
* The
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
* for (const val of list) { log(val); } // 1 2 3
|
|
349
|
-
* ```
|
|
151
|
+
* The function counts the number of occurrences of a given value in a linked list.
|
|
152
|
+
* @param {T} value - The value parameter is the value that you want to count the occurrences of in the linked list.
|
|
153
|
+
* @returns The count of occurrences of the given value in the linked list.
|
|
350
154
|
*/
|
|
351
|
-
|
|
352
|
-
/** Private helper function to reduce duplication of pop() and shift() methods */
|
|
353
|
-
private removeFromAnyEnd;
|
|
155
|
+
countOccurrences(value: T): number;
|
|
354
156
|
}
|