data-structure-typed 1.33.0 → 1.33.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{.eslintrc.json → .eslintrc.js} +2 -1
- package/.github/workflows/ci.yml +15 -3
- package/.github/workflows/release-package.yml +32 -0
- package/{.prettierrc → .prettierrc.js} +1 -1
- package/CHANGELOG.md +5 -1
- package/README.md +196 -257
- package/coverage/coverage-final.json +64 -64
- package/coverage/coverage-summary.json +16 -16
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +1 -16
- package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/avl-tree.js +2 -2
- package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/rb-tree.js +3 -4
- package/dist/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/data-structures/graph/abstract-graph.js +12 -12
- package/dist/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/data-structures/hash/hash-table.js +107 -2
- package/dist/data-structures/hash/hash-table.js.map +1 -1
- package/dist/data-structures/heap/max-heap.js.map +1 -1
- package/dist/data-structures/heap/min-heap.js.map +1 -1
- package/dist/data-structures/linked-list/doubly-linked-list.js +30 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/data-structures/matrix/matrix2d.js +5 -8
- package/dist/data-structures/matrix/matrix2d.js.map +1 -1
- package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/priority-queue.js +6 -6
- package/dist/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/data-structures/queue/deque.js.map +1 -1
- package/docs/index.html +196 -256
- package/docs/modules.html +2 -0
- package/lib/data-structures/binary-tree/abstract-binary-tree.d.ts +8 -18
- package/lib/data-structures/binary-tree/abstract-binary-tree.js +5 -23
- package/lib/data-structures/binary-tree/avl-tree.d.ts +7 -10
- package/lib/data-structures/binary-tree/avl-tree.js +6 -9
- package/lib/data-structures/binary-tree/binary-tree.d.ts +2 -2
- package/lib/data-structures/binary-tree/bst.d.ts +2 -2
- package/lib/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/lib/data-structures/binary-tree/rb-tree.js +3 -3
- package/lib/data-structures/binary-tree/tree-multiset.d.ts +3 -3
- package/lib/data-structures/binary-tree/tree-multiset.js +1 -1
- package/lib/data-structures/graph/abstract-graph.d.ts +10 -10
- package/lib/data-structures/graph/abstract-graph.js +2 -2
- package/lib/data-structures/graph/directed-graph.d.ts +6 -6
- package/lib/data-structures/graph/directed-graph.js +2 -2
- package/lib/data-structures/graph/map-graph.d.ts +6 -6
- package/lib/data-structures/graph/map-graph.js +2 -2
- package/lib/data-structures/graph/undirected-graph.d.ts +6 -6
- package/lib/data-structures/graph/undirected-graph.js +2 -2
- package/lib/data-structures/hash/hash-table.d.ts +61 -1
- package/lib/data-structures/hash/hash-table.js +136 -0
- package/lib/data-structures/heap/heap.d.ts +31 -31
- package/lib/data-structures/heap/heap.js +11 -11
- package/lib/data-structures/heap/max-heap.d.ts +4 -4
- package/lib/data-structures/heap/max-heap.js +1 -1
- package/lib/data-structures/heap/min-heap.d.ts +4 -4
- package/lib/data-structures/heap/min-heap.js +1 -1
- package/lib/data-structures/linked-list/doubly-linked-list.d.ts +93 -54
- package/lib/data-structures/linked-list/doubly-linked-list.js +79 -22
- package/lib/data-structures/linked-list/singly-linked-list.d.ts +46 -46
- package/lib/data-structures/linked-list/singly-linked-list.js +20 -20
- package/lib/data-structures/matrix/matrix.d.ts +3 -3
- package/lib/data-structures/matrix/matrix2d.d.ts +1 -1
- package/lib/data-structures/matrix/matrix2d.js +3 -2
- package/lib/data-structures/priority-queue/max-priority-queue.d.ts +4 -4
- package/lib/data-structures/priority-queue/min-priority-queue.d.ts +4 -4
- package/lib/data-structures/priority-queue/priority-queue.d.ts +26 -26
- package/lib/data-structures/priority-queue/priority-queue.js +8 -8
- package/lib/data-structures/queue/deque.d.ts +30 -30
- package/lib/data-structures/queue/deque.js +7 -7
- package/lib/data-structures/queue/queue.d.ts +27 -27
- package/lib/data-structures/queue/queue.js +8 -8
- package/lib/data-structures/stack/stack.d.ts +15 -15
- package/lib/data-structures/stack/stack.js +6 -6
- package/lib/data-structures/tree/tree.d.ts +7 -7
- package/lib/interfaces/abstract-binary-tree.d.ts +0 -1
- package/lib/interfaces/avl-tree.d.ts +1 -1
- package/lib/types/data-structures/navigator.d.ts +1 -1
- package/package.json +68 -62
- package/src/data-structures/binary-tree/aa-tree.ts +1 -0
- package/src/data-structures/binary-tree/abstract-binary-tree.ts +1608 -0
- package/src/data-structures/binary-tree/avl-tree.ts +307 -0
- package/src/data-structures/binary-tree/b-tree.ts +1 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +76 -0
- package/src/data-structures/binary-tree/binary-tree.ts +47 -0
- package/src/data-structures/binary-tree/bst.ts +537 -0
- package/src/data-structures/binary-tree/index.ts +12 -0
- package/src/data-structures/binary-tree/rb-tree.ts +366 -0
- package/src/data-structures/binary-tree/segment-tree.ts +242 -0
- package/src/data-structures/binary-tree/splay-tree.ts +1 -0
- package/src/data-structures/binary-tree/tree-multiset.ts +700 -0
- package/src/data-structures/binary-tree/two-three-tree.ts +1 -0
- package/src/data-structures/graph/abstract-graph.ts +1040 -0
- package/src/data-structures/graph/directed-graph.ts +470 -0
- package/src/data-structures/graph/index.ts +4 -0
- package/src/data-structures/graph/map-graph.ts +129 -0
- package/src/data-structures/graph/undirected-graph.ts +274 -0
- package/src/data-structures/hash/coordinate-map.ts +67 -0
- package/src/data-structures/hash/coordinate-set.ts +56 -0
- package/src/data-structures/hash/hash-table.ts +157 -0
- package/src/data-structures/hash/index.ts +6 -0
- package/src/data-structures/hash/pair.ts +1 -0
- package/src/data-structures/hash/tree-map.ts +1 -0
- package/src/data-structures/hash/tree-set.ts +1 -0
- package/src/data-structures/heap/heap.ts +212 -0
- package/src/data-structures/heap/index.ts +3 -0
- package/src/data-structures/heap/max-heap.ts +31 -0
- package/src/data-structures/heap/min-heap.ts +32 -0
- package/src/data-structures/index.ts +11 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +636 -0
- package/src/data-structures/linked-list/index.ts +3 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +501 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +1 -0
- package/src/data-structures/matrix/index.ts +4 -0
- package/src/data-structures/matrix/matrix.ts +27 -0
- package/src/data-structures/matrix/matrix2d.ts +213 -0
- package/src/data-structures/matrix/navigator.ts +121 -0
- package/src/data-structures/matrix/vector2d.ts +316 -0
- package/src/data-structures/priority-queue/index.ts +3 -0
- package/src/data-structures/priority-queue/max-priority-queue.ts +56 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +57 -0
- package/src/data-structures/priority-queue/priority-queue.ts +359 -0
- package/src/data-structures/queue/deque.ts +297 -0
- package/src/data-structures/queue/index.ts +2 -0
- package/src/data-structures/queue/queue.ts +191 -0
- package/src/data-structures/stack/index.ts +1 -0
- package/src/data-structures/stack/stack.ts +98 -0
- package/src/data-structures/tree/index.ts +1 -0
- package/src/data-structures/tree/tree.ts +69 -0
- package/src/data-structures/trie/index.ts +1 -0
- package/src/data-structures/trie/trie.ts +225 -0
- package/src/index.ts +4 -0
- package/src/interfaces/abstract-binary-tree.ts +189 -0
- package/src/interfaces/abstract-graph.ts +31 -0
- package/src/interfaces/avl-tree.ts +25 -0
- package/src/interfaces/binary-tree.ts +6 -0
- package/src/interfaces/bst.ts +31 -0
- package/src/interfaces/directed-graph.ts +20 -0
- package/src/interfaces/doubly-linked-list.ts +1 -0
- package/src/interfaces/heap.ts +1 -0
- package/src/interfaces/index.ts +15 -0
- package/src/interfaces/navigator.ts +1 -0
- package/src/interfaces/priority-queue.ts +1 -0
- package/src/interfaces/rb-tree.ts +9 -0
- package/src/interfaces/segment-tree.ts +1 -0
- package/src/interfaces/singly-linked-list.ts +1 -0
- package/src/interfaces/tree-multiset.ts +7 -0
- package/src/interfaces/undirected-graph.ts +6 -0
- package/src/types/data-structures/abstract-binary-tree.ts +50 -0
- package/src/types/data-structures/abstract-graph.ts +11 -0
- package/src/types/data-structures/avl-tree.ts +5 -0
- package/src/types/data-structures/binary-tree.ts +5 -0
- package/src/types/data-structures/bst.ts +13 -0
- package/src/types/data-structures/directed-graph.ts +8 -0
- package/src/types/data-structures/doubly-linked-list.ts +1 -0
- package/src/types/data-structures/heap.ts +5 -0
- package/src/types/data-structures/index.ts +15 -0
- package/src/types/data-structures/map-graph.ts +1 -0
- package/src/types/data-structures/navigator.ts +13 -0
- package/src/types/data-structures/priority-queue.ts +9 -0
- package/src/types/data-structures/rb-tree.ts +8 -0
- package/src/types/data-structures/segment-tree.ts +1 -0
- package/src/types/data-structures/singly-linked-list.ts +1 -0
- package/src/types/data-structures/tree-multiset.ts +6 -0
- package/src/types/helpers.ts +1 -0
- package/src/types/index.ts +3 -0
- package/src/types/utils/index.ts +2 -0
- package/src/types/utils/utils.ts +6 -0
- package/src/types/utils/validate-type.ts +35 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/utils.ts +79 -0
- package/test/integration/avl-tree.test.ts +14 -17
- package/test/integration/bst.test.ts +50 -41
- package/test/integration/heap.test.js +0 -3
- package/test/integration/index.html +6 -6
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +14 -17
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +142 -0
- package/test/unit/data-structures/binary-tree/bst.test.ts +50 -41
- package/test/unit/data-structures/binary-tree/overall.test.ts +36 -28
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +43 -0
- package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +23 -12
- package/test/unit/data-structures/graph/directed-graph.test.ts +27 -25
- package/test/unit/data-structures/graph/map-graph.test.ts +4 -5
- package/test/unit/data-structures/graph/overall.test.ts +10 -11
- package/test/unit/data-structures/graph/undirected-graph.test.ts +0 -1
- package/test/unit/data-structures/hash/coordinate-map.test.ts +54 -0
- package/test/unit/data-structures/hash/coordinate-set.test.ts +41 -0
- package/test/unit/data-structures/hash/hash-table.test.ts +97 -0
- package/test/unit/data-structures/heap/heap.test.ts +7 -8
- package/test/unit/data-structures/heap/max-heap.test.ts +7 -5
- package/test/unit/data-structures/heap/min-heap.test.ts +6 -5
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +8 -9
- package/test/unit/data-structures/linked-list/linked-list.test.ts +2 -4
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +57 -7
- package/test/unit/data-structures/linked-list/skip-linked-list.test.ts +3 -3
- package/test/unit/data-structures/matrix/matrix.test.ts +54 -0
- package/test/unit/data-structures/matrix/matrix2d.test.ts +138 -0
- package/test/unit/data-structures/matrix/navigator.test.ts +79 -0
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +5 -7
- package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +13 -13
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +8 -8
- package/test/unit/data-structures/queue/deque.test.ts +130 -0
- package/test/unit/data-structures/queue/queue.test.ts +167 -4
- package/test/unit/data-structures/stack/stack.test.ts +67 -0
- package/test/unit/data-structures/tree/tree.test.ts +39 -0
- package/test/unit/data-structures/trie/trie.test.ts +95 -0
- package/test/utils/magnitude.ts +3 -3
- package/tsconfig.json +3 -12
- package/tsconfig.prod.json +25 -0
- package/umd/bundle.min.js +1 -1
- package/umd/bundle.min.js.map +1 -1
- package/.auto-changelog +0 -9
- package/.gitattributes +0 -112
- package/.idea/data-structure-typed.iml +0 -19
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/.prettierignore +0 -6
- package/webpack.config.js +0 -28
|
@@ -5,66 +5,100 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
export declare class DoublyLinkedListNode<
|
|
8
|
+
export declare class DoublyLinkedListNode<E = any> {
|
|
9
9
|
/**
|
|
10
10
|
* The constructor function initializes the value, next, and previous properties of an object.
|
|
11
|
-
* @param {
|
|
12
|
-
* is defined as a generic type "
|
|
11
|
+
* @param {E} val - The "val" parameter is the value that will be stored in the node. It can be of any data type, as it
|
|
12
|
+
* is defined as a generic type "E".
|
|
13
13
|
*/
|
|
14
|
-
constructor(val:
|
|
14
|
+
constructor(val: E);
|
|
15
15
|
private _val;
|
|
16
|
-
get val():
|
|
17
|
-
set val(value:
|
|
16
|
+
get val(): E;
|
|
17
|
+
set val(value: E);
|
|
18
18
|
private _next;
|
|
19
|
-
get next(): DoublyLinkedListNode<
|
|
20
|
-
set next(value: DoublyLinkedListNode<
|
|
19
|
+
get next(): DoublyLinkedListNode<E> | null;
|
|
20
|
+
set next(value: DoublyLinkedListNode<E> | null);
|
|
21
21
|
private _prev;
|
|
22
|
-
get prev(): DoublyLinkedListNode<
|
|
23
|
-
set prev(value: DoublyLinkedListNode<
|
|
22
|
+
get prev(): DoublyLinkedListNode<E> | null;
|
|
23
|
+
set prev(value: DoublyLinkedListNode<E> | null);
|
|
24
24
|
}
|
|
25
|
-
export declare class DoublyLinkedList<
|
|
25
|
+
export declare class DoublyLinkedList<E = any> {
|
|
26
26
|
/**
|
|
27
27
|
* The constructor initializes the linked list with an empty head, tail, and length.
|
|
28
28
|
*/
|
|
29
29
|
constructor();
|
|
30
30
|
private _head;
|
|
31
|
-
get head(): DoublyLinkedListNode<
|
|
32
|
-
set head(value: DoublyLinkedListNode<
|
|
31
|
+
get head(): DoublyLinkedListNode<E> | null;
|
|
32
|
+
set head(value: DoublyLinkedListNode<E> | null);
|
|
33
33
|
private _tail;
|
|
34
|
-
get tail(): DoublyLinkedListNode<
|
|
35
|
-
set tail(value: DoublyLinkedListNode<
|
|
34
|
+
get tail(): DoublyLinkedListNode<E> | null;
|
|
35
|
+
set tail(value: DoublyLinkedListNode<E> | null);
|
|
36
36
|
private _length;
|
|
37
37
|
get length(): number;
|
|
38
38
|
/**
|
|
39
39
|
* The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
|
|
40
40
|
* given array.
|
|
41
|
-
* @param {
|
|
41
|
+
* @param {E[]} data - The `data` parameter is an array of elements of type `E`.
|
|
42
42
|
* @returns The `fromArray` function returns a DoublyLinkedList object.
|
|
43
43
|
*/
|
|
44
|
-
static fromArray<
|
|
44
|
+
static fromArray<E>(data: E[]): DoublyLinkedList<E>;
|
|
45
45
|
/**
|
|
46
46
|
* The push function adds a new node with the given value to the end of the doubly linked list.
|
|
47
|
-
* @param {
|
|
47
|
+
* @param {E} val - The value to be added to the linked list.
|
|
48
48
|
*/
|
|
49
|
-
push(val:
|
|
49
|
+
push(val: E): void;
|
|
50
|
+
/**
|
|
51
|
+
* The addLast function adds a new node with the given value to the end of the doubly linked list.
|
|
52
|
+
* @param {E} val - The value to be added to the linked list.
|
|
53
|
+
*/
|
|
54
|
+
addLast(val: E): void;
|
|
50
55
|
/**
|
|
51
56
|
* The `pop()` function removes and returns the value of the last node in a doubly linked list.
|
|
52
57
|
* @returns The method is returning the value of the removed node (removedNode.val) if the list is not empty. If the
|
|
53
58
|
* list is empty, it returns null.
|
|
54
59
|
*/
|
|
55
|
-
pop():
|
|
60
|
+
pop(): E | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* The `pollLast()` function removes and returns the value of the last node in a doubly linked list.
|
|
63
|
+
* @returns The method is returning the value of the removed node (removedNode.val) if the list is not empty. If the
|
|
64
|
+
* list is empty, it returns null.
|
|
65
|
+
*/
|
|
66
|
+
pollLast(): E | undefined;
|
|
56
67
|
/**
|
|
57
68
|
* The `shift()` function removes and returns the value of the first node in a doubly linked list.
|
|
58
69
|
* @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
|
|
59
70
|
* list.
|
|
60
71
|
*/
|
|
61
|
-
shift():
|
|
72
|
+
shift(): E | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* The `pollFirst()` function removes and returns the value of the first node in a doubly linked list.
|
|
75
|
+
* @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
|
|
76
|
+
* list.
|
|
77
|
+
*/
|
|
78
|
+
pollFirst(): E | undefined;
|
|
62
79
|
/**
|
|
63
80
|
* The unshift function adds a new node with the given value to the beginning of a doubly linked list.
|
|
64
|
-
* @param {
|
|
81
|
+
* @param {E} val - The `val` parameter represents the value of the new node that will be added to the beginning of the
|
|
65
82
|
* doubly linked list.
|
|
66
83
|
*/
|
|
67
|
-
unshift(val:
|
|
84
|
+
unshift(val: E): void;
|
|
85
|
+
/**
|
|
86
|
+
* The addFirst function adds a new node with the given value to the beginning of a doubly linked list.
|
|
87
|
+
* @param {E} val - The `val` parameter represents the value of the new node that will be added to the beginning of the
|
|
88
|
+
* doubly linked list.
|
|
89
|
+
*/
|
|
90
|
+
addFirst(val: E): void;
|
|
91
|
+
/**
|
|
92
|
+
* The `peekFirst` function returns the first node in a doubly linked list, or null if the list is empty.
|
|
93
|
+
* @returns The method `peekFirst()` returns the first node of the doubly linked list, or `null` if the list is empty.
|
|
94
|
+
*/
|
|
95
|
+
peekFirst(): E | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* The `peekLast` function returns the last node in a doubly linked list, or null if the list is empty.
|
|
98
|
+
* @returns The method `peekLast()` returns the last node of the doubly linked list, or `null` if the list is empty.
|
|
99
|
+
*/
|
|
100
|
+
peekLast(): E | undefined;
|
|
101
|
+
get size(): number;
|
|
68
102
|
/**
|
|
69
103
|
* The `getAt` function returns the value at a specified index in a linked list, or null if the index is out of bounds.
|
|
70
104
|
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
@@ -72,34 +106,34 @@ export declare class DoublyLinkedList<T = any> {
|
|
|
72
106
|
* @returns The method is returning the value at the specified index in the linked list. If the index is out of bounds
|
|
73
107
|
* or the linked list is empty, it will return null.
|
|
74
108
|
*/
|
|
75
|
-
getAt(index: number):
|
|
109
|
+
getAt(index: number): E | undefined;
|
|
76
110
|
/**
|
|
77
111
|
* The function `getNodeAt` returns the node at a given index in a doubly linked list, or null if the index is out of
|
|
78
112
|
* range.
|
|
79
113
|
* @param {number} index - The `index` parameter is a number that represents the position of the node we want to
|
|
80
114
|
* retrieve from the doubly linked list. It indicates the zero-based index of the node we want to access.
|
|
81
|
-
* @returns The method `getNodeAt(index: number)` returns a `DoublyLinkedListNode<
|
|
115
|
+
* @returns The method `getNodeAt(index: number)` returns a `DoublyLinkedListNode<E>` object if the index is within the
|
|
82
116
|
* valid range of the linked list, otherwise it returns `null`.
|
|
83
117
|
*/
|
|
84
|
-
getNodeAt(index: number): DoublyLinkedListNode<
|
|
118
|
+
getNodeAt(index: number): DoublyLinkedListNode<E> | null;
|
|
85
119
|
/**
|
|
86
120
|
* The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
|
|
87
121
|
* node if found, otherwise it returns null.
|
|
88
|
-
* @param {
|
|
89
|
-
* @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<
|
|
122
|
+
* @param {E} val - The `val` parameter is the value that we want to search for in the doubly linked list.
|
|
123
|
+
* @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<E>` if a node with the specified value `val`
|
|
90
124
|
* is found in the linked list. If no such node is found, it returns `null`.
|
|
91
125
|
*/
|
|
92
|
-
findNode(val:
|
|
126
|
+
findNode(val: E): DoublyLinkedListNode<E> | null;
|
|
93
127
|
/**
|
|
94
128
|
* The `insert` function inserts a value at a specified index in a doubly linked list.
|
|
95
129
|
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
96
130
|
* DoublyLinkedList. It is of type number.
|
|
97
|
-
* @param {
|
|
131
|
+
* @param {E} val - The `val` parameter represents the value that you want to insert into the Doubly Linked List at the
|
|
98
132
|
* specified index.
|
|
99
133
|
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
|
|
100
134
|
* if the index is out of bounds.
|
|
101
135
|
*/
|
|
102
|
-
insertAt(index: number, val:
|
|
136
|
+
insertAt(index: number, val: E): boolean;
|
|
103
137
|
/**
|
|
104
138
|
* The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
|
|
105
139
|
* @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
|
|
@@ -107,48 +141,53 @@ export declare class DoublyLinkedList<T = any> {
|
|
|
107
141
|
* @returns The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of
|
|
108
142
|
* bounds.
|
|
109
143
|
*/
|
|
110
|
-
deleteAt(index: number):
|
|
111
|
-
delete(valOrNode:
|
|
112
|
-
delete(valOrNode: DoublyLinkedListNode<
|
|
144
|
+
deleteAt(index: number): E | undefined;
|
|
145
|
+
delete(valOrNode: E): boolean;
|
|
146
|
+
delete(valOrNode: DoublyLinkedListNode<E>): boolean;
|
|
113
147
|
/**
|
|
114
148
|
* The `toArray` function converts a linked list into an array.
|
|
115
|
-
* @returns The `toArray()` method is returning an array of type `
|
|
149
|
+
* @returns The `toArray()` method is returning an array of type `E[]`.
|
|
150
|
+
*/
|
|
151
|
+
toArray(): E[];
|
|
152
|
+
/**
|
|
153
|
+
* The function checks if a variable has a length greater than zero and returns a boolean value.
|
|
154
|
+
* @returns A boolean value is being returned.
|
|
116
155
|
*/
|
|
117
|
-
|
|
156
|
+
isEmpty(): boolean;
|
|
118
157
|
/**
|
|
119
158
|
* The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively.
|
|
120
159
|
*/
|
|
121
160
|
clear(): void;
|
|
122
161
|
/**
|
|
123
162
|
* The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
|
|
124
|
-
* @param callback - A function that takes a value of type
|
|
163
|
+
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
125
164
|
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
|
|
126
165
|
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
|
|
127
166
|
* the callback function. If no element satisfies the condition, it returns `null`.
|
|
128
167
|
*/
|
|
129
|
-
find(callback: (val:
|
|
168
|
+
find(callback: (val: E) => boolean): E | null;
|
|
130
169
|
/**
|
|
131
170
|
* The function returns the index of the first occurrence of a given value in a linked list.
|
|
132
|
-
* @param {
|
|
171
|
+
* @param {E} val - The parameter `val` is of type `E`, which means it can be any data type. It represents the value
|
|
133
172
|
* that we are searching for in the linked list.
|
|
134
173
|
* @returns The method `indexOf` returns the index of the first occurrence of the specified value `val` in the linked
|
|
135
174
|
* list. If the value is not found, it returns -1.
|
|
136
175
|
*/
|
|
137
|
-
indexOf(val:
|
|
176
|
+
indexOf(val: E): number;
|
|
138
177
|
/**
|
|
139
178
|
* The `findLast` function iterates through a linked list from the last node to the first node and returns the last
|
|
140
179
|
* value that satisfies the given callback function, or null if no value satisfies the callback.
|
|
141
|
-
* @param callback - A function that takes a value of type
|
|
180
|
+
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
142
181
|
* function is used to determine whether a given value satisfies a certain condition.
|
|
143
182
|
* @returns The method `findLast` returns the last value in the linked list that satisfies the condition specified by
|
|
144
183
|
* the callback function. If no value satisfies the condition, it returns `null`.
|
|
145
184
|
*/
|
|
146
|
-
findLast(callback: (val:
|
|
185
|
+
findLast(callback: (val: E) => boolean): E | null;
|
|
147
186
|
/**
|
|
148
187
|
* The `toArrayReverse` function converts a doubly linked list into an array in reverse order.
|
|
149
|
-
* @returns The `toArrayReverse()` function returns an array of type `
|
|
188
|
+
* @returns The `toArrayReverse()` function returns an array of type `E[]`.
|
|
150
189
|
*/
|
|
151
|
-
toArrayReverse():
|
|
190
|
+
toArrayReverse(): E[];
|
|
152
191
|
/**
|
|
153
192
|
* The `reverse` function reverses the order of the elements in a doubly linked list.
|
|
154
193
|
*/
|
|
@@ -159,24 +198,24 @@ export declare class DoublyLinkedList<T = any> {
|
|
|
159
198
|
* represents the value of the current node in the linked list, and the index argument represents the index of the
|
|
160
199
|
* current node in the linked list.
|
|
161
200
|
*/
|
|
162
|
-
forEach(callback: (val:
|
|
201
|
+
forEach(callback: (val: E, index: number) => void): void;
|
|
163
202
|
/**
|
|
164
203
|
* The `map` function takes a callback function and applies it to each element in the DoublyLinkedList, returning a new
|
|
165
204
|
* DoublyLinkedList with the transformed values.
|
|
166
|
-
* @param callback - The callback parameter is a function that takes a value of type
|
|
205
|
+
* @param callback - The callback parameter is a function that takes a value of type E (the type of values stored in
|
|
167
206
|
* the original DoublyLinkedList) and returns a value of type U (the type of values that will be stored in the mapped
|
|
168
207
|
* DoublyLinkedList).
|
|
169
208
|
* @returns The `map` function is returning a new instance of `DoublyLinkedList<U>` that contains the mapped values.
|
|
170
209
|
*/
|
|
171
|
-
map<U>(callback: (val:
|
|
210
|
+
map<U>(callback: (val: E) => U): DoublyLinkedList<U>;
|
|
172
211
|
/**
|
|
173
212
|
* The `filter` function iterates through a DoublyLinkedList and returns a new DoublyLinkedList containing only the
|
|
174
213
|
* elements that satisfy the given callback function.
|
|
175
|
-
* @param callback - The `callback` parameter is a function that takes a value of type `
|
|
214
|
+
* @param callback - The `callback` parameter is a function that takes a value of type `E` and returns a boolean value.
|
|
176
215
|
* It is used to determine whether a value should be included in the filtered list or not.
|
|
177
216
|
* @returns The filtered list, which is an instance of the DoublyLinkedList class.
|
|
178
217
|
*/
|
|
179
|
-
filter(callback: (val:
|
|
218
|
+
filter(callback: (val: E) => boolean): DoublyLinkedList<E>;
|
|
180
219
|
/**
|
|
181
220
|
* The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
|
|
182
221
|
* single value.
|
|
@@ -187,9 +226,9 @@ export declare class DoublyLinkedList<T = any> {
|
|
|
187
226
|
* @returns The `reduce` method is returning the final value of the accumulator after iterating through all the
|
|
188
227
|
* elements in the linked list.
|
|
189
228
|
*/
|
|
190
|
-
reduce<U>(callback: (accumulator: U, val:
|
|
191
|
-
insertAfter(existingValueOrNode:
|
|
192
|
-
insertAfter(existingValueOrNode: DoublyLinkedListNode<
|
|
193
|
-
insertBefore(existingValueOrNode:
|
|
194
|
-
insertBefore(existingValueOrNode: DoublyLinkedListNode<
|
|
229
|
+
reduce<U>(callback: (accumulator: U, val: E) => U, initialValue: U): U;
|
|
230
|
+
insertAfter(existingValueOrNode: E, newValue: E): boolean;
|
|
231
|
+
insertAfter(existingValueOrNode: DoublyLinkedListNode<E>, newValue: E): boolean;
|
|
232
|
+
insertBefore(existingValueOrNode: E, newValue: E): boolean;
|
|
233
|
+
insertBefore(existingValueOrNode: DoublyLinkedListNode<E>, newValue: E): boolean;
|
|
195
234
|
}
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
export class DoublyLinkedListNode {
|
|
9
9
|
/**
|
|
10
10
|
* The constructor function initializes the value, next, and previous properties of an object.
|
|
11
|
-
* @param {
|
|
12
|
-
* is defined as a generic type "
|
|
11
|
+
* @param {E} val - The "val" parameter is the value that will be stored in the node. It can be of any data type, as it
|
|
12
|
+
* is defined as a generic type "E".
|
|
13
13
|
*/
|
|
14
14
|
constructor(val) {
|
|
15
15
|
this._val = val;
|
|
@@ -62,7 +62,7 @@ export class DoublyLinkedList {
|
|
|
62
62
|
/**
|
|
63
63
|
* The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
|
|
64
64
|
* given array.
|
|
65
|
-
* @param {
|
|
65
|
+
* @param {E[]} data - The `data` parameter is an array of elements of type `E`.
|
|
66
66
|
* @returns The `fromArray` function returns a DoublyLinkedList object.
|
|
67
67
|
*/
|
|
68
68
|
static fromArray(data) {
|
|
@@ -74,7 +74,7 @@ export class DoublyLinkedList {
|
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
76
|
* The push function adds a new node with the given value to the end of the doubly linked list.
|
|
77
|
-
* @param {
|
|
77
|
+
* @param {E} val - The value to be added to the linked list.
|
|
78
78
|
*/
|
|
79
79
|
push(val) {
|
|
80
80
|
const newNode = new DoublyLinkedListNode(val);
|
|
@@ -89,6 +89,13 @@ export class DoublyLinkedList {
|
|
|
89
89
|
}
|
|
90
90
|
this._length++;
|
|
91
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* The addLast function adds a new node with the given value to the end of the doubly linked list.
|
|
94
|
+
* @param {E} val - The value to be added to the linked list.
|
|
95
|
+
*/
|
|
96
|
+
addLast(val) {
|
|
97
|
+
this.push(val);
|
|
98
|
+
}
|
|
92
99
|
/**
|
|
93
100
|
* The `pop()` function removes and returns the value of the last node in a doubly linked list.
|
|
94
101
|
* @returns The method is returning the value of the removed node (removedNode.val) if the list is not empty. If the
|
|
@@ -109,6 +116,14 @@ export class DoublyLinkedList {
|
|
|
109
116
|
this._length--;
|
|
110
117
|
return removedNode.val;
|
|
111
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* The `pollLast()` function removes and returns the value of the last node in a doubly linked list.
|
|
121
|
+
* @returns The method is returning the value of the removed node (removedNode.val) if the list is not empty. If the
|
|
122
|
+
* list is empty, it returns null.
|
|
123
|
+
*/
|
|
124
|
+
pollLast() {
|
|
125
|
+
return this.pop();
|
|
126
|
+
}
|
|
112
127
|
/**
|
|
113
128
|
* The `shift()` function removes and returns the value of the first node in a doubly linked list.
|
|
114
129
|
* @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
|
|
@@ -129,9 +144,17 @@ export class DoublyLinkedList {
|
|
|
129
144
|
this._length--;
|
|
130
145
|
return removedNode.val;
|
|
131
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* The `pollFirst()` function removes and returns the value of the first node in a doubly linked list.
|
|
149
|
+
* @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
|
|
150
|
+
* list.
|
|
151
|
+
*/
|
|
152
|
+
pollFirst() {
|
|
153
|
+
return this.shift();
|
|
154
|
+
}
|
|
132
155
|
/**
|
|
133
156
|
* The unshift function adds a new node with the given value to the beginning of a doubly linked list.
|
|
134
|
-
* @param {
|
|
157
|
+
* @param {E} val - The `val` parameter represents the value of the new node that will be added to the beginning of the
|
|
135
158
|
* doubly linked list.
|
|
136
159
|
*/
|
|
137
160
|
unshift(val) {
|
|
@@ -147,6 +170,33 @@ export class DoublyLinkedList {
|
|
|
147
170
|
}
|
|
148
171
|
this._length++;
|
|
149
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* The addFirst function adds a new node with the given value to the beginning of a doubly linked list.
|
|
175
|
+
* @param {E} val - The `val` parameter represents the value of the new node that will be added to the beginning of the
|
|
176
|
+
* doubly linked list.
|
|
177
|
+
*/
|
|
178
|
+
addFirst(val) {
|
|
179
|
+
this.unshift(val);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* The `peekFirst` function returns the first node in a doubly linked list, or null if the list is empty.
|
|
183
|
+
* @returns The method `peekFirst()` returns the first node of the doubly linked list, or `null` if the list is empty.
|
|
184
|
+
*/
|
|
185
|
+
peekFirst() {
|
|
186
|
+
var _a;
|
|
187
|
+
return (_a = this.head) === null || _a === void 0 ? void 0 : _a.val;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* The `peekLast` function returns the last node in a doubly linked list, or null if the list is empty.
|
|
191
|
+
* @returns The method `peekLast()` returns the last node of the doubly linked list, or `null` if the list is empty.
|
|
192
|
+
*/
|
|
193
|
+
peekLast() {
|
|
194
|
+
var _a;
|
|
195
|
+
return (_a = this.tail) === null || _a === void 0 ? void 0 : _a.val;
|
|
196
|
+
}
|
|
197
|
+
get size() {
|
|
198
|
+
return this.length;
|
|
199
|
+
}
|
|
150
200
|
/**
|
|
151
201
|
* The `getAt` function returns the value at a specified index in a linked list, or null if the index is out of bounds.
|
|
152
202
|
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
@@ -168,7 +218,7 @@ export class DoublyLinkedList {
|
|
|
168
218
|
* range.
|
|
169
219
|
* @param {number} index - The `index` parameter is a number that represents the position of the node we want to
|
|
170
220
|
* retrieve from the doubly linked list. It indicates the zero-based index of the node we want to access.
|
|
171
|
-
* @returns The method `getNodeAt(index: number)` returns a `DoublyLinkedListNode<
|
|
221
|
+
* @returns The method `getNodeAt(index: number)` returns a `DoublyLinkedListNode<E>` object if the index is within the
|
|
172
222
|
* valid range of the linked list, otherwise it returns `null`.
|
|
173
223
|
*/
|
|
174
224
|
getNodeAt(index) {
|
|
@@ -183,8 +233,8 @@ export class DoublyLinkedList {
|
|
|
183
233
|
/**
|
|
184
234
|
* The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
|
|
185
235
|
* node if found, otherwise it returns null.
|
|
186
|
-
* @param {
|
|
187
|
-
* @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<
|
|
236
|
+
* @param {E} val - The `val` parameter is the value that we want to search for in the doubly linked list.
|
|
237
|
+
* @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<E>` if a node with the specified value `val`
|
|
188
238
|
* is found in the linked list. If no such node is found, it returns `null`.
|
|
189
239
|
*/
|
|
190
240
|
findNode(val) {
|
|
@@ -201,7 +251,7 @@ export class DoublyLinkedList {
|
|
|
201
251
|
* The `insert` function inserts a value at a specified index in a doubly linked list.
|
|
202
252
|
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
203
253
|
* DoublyLinkedList. It is of type number.
|
|
204
|
-
* @param {
|
|
254
|
+
* @param {E} val - The `val` parameter represents the value that you want to insert into the Doubly Linked List at the
|
|
205
255
|
* specified index.
|
|
206
256
|
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
|
|
207
257
|
* if the index is out of bounds.
|
|
@@ -251,8 +301,8 @@ export class DoublyLinkedList {
|
|
|
251
301
|
}
|
|
252
302
|
/**
|
|
253
303
|
* The `delete` function removes a node from a doubly linked list based on either the node itself or its value.
|
|
254
|
-
* @param {
|
|
255
|
-
* a `DoublyLinkedListNode<
|
|
304
|
+
* @param {E | DoublyLinkedListNode<E>} valOrNode - The `valOrNode` parameter can accept either a value of type `E` or
|
|
305
|
+
* a `DoublyLinkedListNode<E>` object.
|
|
256
306
|
* @returns The `delete` method returns a boolean value. It returns `true` if the value or node was successfully
|
|
257
307
|
* deleted from the doubly linked list, and `false` if the value or node was not found in the list.
|
|
258
308
|
*/
|
|
@@ -284,7 +334,7 @@ export class DoublyLinkedList {
|
|
|
284
334
|
}
|
|
285
335
|
/**
|
|
286
336
|
* The `toArray` function converts a linked list into an array.
|
|
287
|
-
* @returns The `toArray()` method is returning an array of type `
|
|
337
|
+
* @returns The `toArray()` method is returning an array of type `E[]`.
|
|
288
338
|
*/
|
|
289
339
|
toArray() {
|
|
290
340
|
const array = [];
|
|
@@ -295,6 +345,13 @@ export class DoublyLinkedList {
|
|
|
295
345
|
}
|
|
296
346
|
return array;
|
|
297
347
|
}
|
|
348
|
+
/**
|
|
349
|
+
* The function checks if a variable has a length greater than zero and returns a boolean value.
|
|
350
|
+
* @returns A boolean value is being returned.
|
|
351
|
+
*/
|
|
352
|
+
isEmpty() {
|
|
353
|
+
return this.length === 0;
|
|
354
|
+
}
|
|
298
355
|
/**
|
|
299
356
|
* The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively.
|
|
300
357
|
*/
|
|
@@ -305,7 +362,7 @@ export class DoublyLinkedList {
|
|
|
305
362
|
}
|
|
306
363
|
/**
|
|
307
364
|
* The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
|
|
308
|
-
* @param callback - A function that takes a value of type
|
|
365
|
+
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
309
366
|
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
|
|
310
367
|
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
|
|
311
368
|
* the callback function. If no element satisfies the condition, it returns `null`.
|
|
@@ -322,7 +379,7 @@ export class DoublyLinkedList {
|
|
|
322
379
|
}
|
|
323
380
|
/**
|
|
324
381
|
* The function returns the index of the first occurrence of a given value in a linked list.
|
|
325
|
-
* @param {
|
|
382
|
+
* @param {E} val - The parameter `val` is of type `E`, which means it can be any data type. It represents the value
|
|
326
383
|
* that we are searching for in the linked list.
|
|
327
384
|
* @returns The method `indexOf` returns the index of the first occurrence of the specified value `val` in the linked
|
|
328
385
|
* list. If the value is not found, it returns -1.
|
|
@@ -342,7 +399,7 @@ export class DoublyLinkedList {
|
|
|
342
399
|
/**
|
|
343
400
|
* The `findLast` function iterates through a linked list from the last node to the first node and returns the last
|
|
344
401
|
* value that satisfies the given callback function, or null if no value satisfies the callback.
|
|
345
|
-
* @param callback - A function that takes a value of type
|
|
402
|
+
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
346
403
|
* function is used to determine whether a given value satisfies a certain condition.
|
|
347
404
|
* @returns The method `findLast` returns the last value in the linked list that satisfies the condition specified by
|
|
348
405
|
* the callback function. If no value satisfies the condition, it returns `null`.
|
|
@@ -359,7 +416,7 @@ export class DoublyLinkedList {
|
|
|
359
416
|
}
|
|
360
417
|
/**
|
|
361
418
|
* The `toArrayReverse` function converts a doubly linked list into an array in reverse order.
|
|
362
|
-
* @returns The `toArrayReverse()` function returns an array of type `
|
|
419
|
+
* @returns The `toArrayReverse()` function returns an array of type `E[]`.
|
|
363
420
|
*/
|
|
364
421
|
toArrayReverse() {
|
|
365
422
|
const array = [];
|
|
@@ -400,7 +457,7 @@ export class DoublyLinkedList {
|
|
|
400
457
|
/**
|
|
401
458
|
* The `map` function takes a callback function and applies it to each element in the DoublyLinkedList, returning a new
|
|
402
459
|
* DoublyLinkedList with the transformed values.
|
|
403
|
-
* @param callback - The callback parameter is a function that takes a value of type
|
|
460
|
+
* @param callback - The callback parameter is a function that takes a value of type E (the type of values stored in
|
|
404
461
|
* the original DoublyLinkedList) and returns a value of type U (the type of values that will be stored in the mapped
|
|
405
462
|
* DoublyLinkedList).
|
|
406
463
|
* @returns The `map` function is returning a new instance of `DoublyLinkedList<U>` that contains the mapped values.
|
|
@@ -417,7 +474,7 @@ export class DoublyLinkedList {
|
|
|
417
474
|
/**
|
|
418
475
|
* The `filter` function iterates through a DoublyLinkedList and returns a new DoublyLinkedList containing only the
|
|
419
476
|
* elements that satisfy the given callback function.
|
|
420
|
-
* @param callback - The `callback` parameter is a function that takes a value of type `
|
|
477
|
+
* @param callback - The `callback` parameter is a function that takes a value of type `E` and returns a boolean value.
|
|
421
478
|
* It is used to determine whether a value should be included in the filtered list or not.
|
|
422
479
|
* @returns The filtered list, which is an instance of the DoublyLinkedList class.
|
|
423
480
|
*/
|
|
@@ -453,10 +510,10 @@ export class DoublyLinkedList {
|
|
|
453
510
|
}
|
|
454
511
|
/**
|
|
455
512
|
* The `insertAfter` function inserts a new node with a given value after an existing node in a doubly linked list.
|
|
456
|
-
* @param {
|
|
513
|
+
* @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
|
|
457
514
|
* after which the new value will be inserted. It can be either the value of the existing node or the existing node
|
|
458
515
|
* itself.
|
|
459
|
-
* @param {
|
|
516
|
+
* @param {E} newValue - The value that you want to insert into the doubly linked list.
|
|
460
517
|
* @returns The method returns a boolean value. It returns true if the insertion is successful, and false if the
|
|
461
518
|
* existing value or node is not found in the doubly linked list.
|
|
462
519
|
*/
|
|
@@ -486,10 +543,10 @@ export class DoublyLinkedList {
|
|
|
486
543
|
}
|
|
487
544
|
/**
|
|
488
545
|
* The `insertBefore` function inserts a new value before an existing value or node in a doubly linked list.
|
|
489
|
-
* @param {
|
|
546
|
+
* @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
|
|
490
547
|
* before which the new value will be inserted. It can be either the value of the existing node or the existing node
|
|
491
548
|
* itself.
|
|
492
|
-
* @param {
|
|
549
|
+
* @param {E} newValue - The `newValue` parameter represents the value that you want to insert into the doubly linked
|
|
493
550
|
* list.
|
|
494
551
|
* @returns The method returns a boolean value. It returns `true` if the insertion is successful, and `false` if the
|
|
495
552
|
* insertion fails.
|