data-structure-typed 1.35.0 → 1.40.0-rc
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/.github/workflows/ci.yml +3 -0
- package/CHANGELOG.md +3 -1
- package/CONTRIBUTING.md +18 -0
- package/dist/data-structures/binary-tree/aa-tree.d.ts +2 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +527 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +323 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/avl-tree.d.ts +94 -0
- package/dist/data-structures/binary-tree/avl-tree.js +90 -3
- package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/b-tree.d.ts +2 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +46 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +36 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/binary-tree.d.ts +31 -0
- package/dist/data-structures/binary-tree/binary-tree.js +21 -0
- package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/bst.d.ts +133 -0
- package/dist/data-structures/binary-tree/bst.js +114 -0
- package/dist/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/data-structures/binary-tree/index.d.ts +12 -0
- package/dist/data-structures/binary-tree/rb-tree.d.ts +13 -0
- package/dist/data-structures/binary-tree/segment-tree.d.ts +83 -0
- package/dist/data-structures/binary-tree/segment-tree.js +45 -0
- package/dist/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/splay-tree.d.ts +2 -0
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +209 -0
- package/dist/data-structures/binary-tree/tree-multiset.js +178 -0
- package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
- package/dist/data-structures/binary-tree/two-three-tree.d.ts +2 -0
- package/dist/data-structures/graph/abstract-graph.d.ts +332 -0
- package/dist/data-structures/graph/abstract-graph.js +269 -4
- package/dist/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/data-structures/graph/directed-graph.d.ts +200 -0
- package/dist/data-structures/graph/directed-graph.js +167 -0
- package/dist/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/data-structures/graph/index.d.ts +4 -0
- package/dist/data-structures/graph/map-graph.d.ts +79 -0
- package/dist/data-structures/graph/map-graph.js +54 -0
- package/dist/data-structures/graph/map-graph.js.map +1 -1
- package/dist/data-structures/graph/undirected-graph.d.ts +127 -0
- package/dist/data-structures/graph/undirected-graph.js +105 -0
- package/dist/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/data-structures/hash/coordinate-map.d.ts +45 -0
- package/dist/data-structures/hash/coordinate-map.js +35 -0
- package/dist/data-structures/hash/coordinate-map.js.map +1 -1
- package/dist/data-structures/hash/coordinate-set.d.ts +37 -0
- package/dist/data-structures/hash/coordinate-set.js +28 -0
- package/dist/data-structures/hash/coordinate-set.js.map +1 -1
- package/dist/data-structures/hash/hash-map.d.ts +56 -0
- package/dist/data-structures/hash/hash-map.js +29 -1
- package/dist/data-structures/hash/hash-map.js.map +1 -1
- package/dist/data-structures/hash/hash-table.d.ts +106 -0
- package/dist/data-structures/hash/hash-table.js +88 -6
- package/dist/data-structures/hash/hash-table.js.map +1 -1
- package/dist/data-structures/hash/index.d.ts +7 -0
- package/dist/data-structures/hash/pair.d.ts +2 -0
- package/dist/data-structures/hash/tree-map.d.ts +2 -0
- package/dist/data-structures/hash/tree-set.d.ts +2 -0
- package/dist/data-structures/heap/heap.d.ts +83 -0
- package/dist/data-structures/heap/heap.js +62 -0
- package/dist/data-structures/heap/heap.js.map +1 -1
- package/dist/data-structures/heap/index.d.ts +3 -0
- package/dist/data-structures/heap/max-heap.d.ts +23 -0
- package/dist/data-structures/heap/max-heap.js +16 -0
- package/dist/data-structures/heap/max-heap.js.map +1 -1
- package/dist/data-structures/heap/min-heap.d.ts +24 -0
- package/dist/data-structures/heap/min-heap.js +17 -0
- package/dist/data-structures/heap/min-heap.js.map +1 -1
- package/dist/data-structures/index.d.ts +11 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +234 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js +202 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/data-structures/linked-list/index.d.ts +3 -0
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +157 -0
- package/dist/data-structures/linked-list/singly-linked-list.js +135 -0
- package/dist/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +61 -0
- package/dist/data-structures/linked-list/skip-linked-list.js +36 -0
- package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/data-structures/matrix/index.d.ts +4 -0
- package/dist/data-structures/matrix/matrix.d.ts +21 -0
- package/dist/data-structures/matrix/matrix.js +15 -0
- package/dist/data-structures/matrix/matrix.js.map +1 -1
- package/dist/data-structures/matrix/matrix2d.d.ts +108 -0
- package/dist/data-structures/matrix/matrix2d.js +91 -2
- package/dist/data-structures/matrix/matrix2d.js.map +1 -1
- package/dist/data-structures/matrix/navigator.d.ts +52 -0
- package/dist/data-structures/matrix/navigator.js +28 -0
- package/dist/data-structures/matrix/navigator.js.map +1 -1
- package/dist/data-structures/matrix/vector2d.d.ts +201 -0
- package/dist/data-structures/matrix/vector2d.js +188 -1
- package/dist/data-structures/matrix/vector2d.js.map +1 -1
- package/dist/data-structures/priority-queue/index.d.ts +3 -0
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +15 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +18 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +15 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +19 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/priority-queue.d.ts +180 -0
- package/dist/data-structures/priority-queue/priority-queue.js +141 -0
- package/dist/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/data-structures/queue/deque.d.ts +165 -0
- package/dist/data-structures/queue/deque.js +124 -0
- package/dist/data-structures/queue/deque.js.map +1 -1
- package/dist/data-structures/queue/index.d.ts +2 -0
- package/dist/data-structures/queue/queue.d.ts +107 -0
- package/dist/data-structures/queue/queue.js +80 -0
- package/dist/data-structures/queue/queue.js.map +1 -1
- package/dist/data-structures/stack/index.d.ts +1 -0
- package/dist/data-structures/stack/stack.d.ts +63 -0
- package/dist/data-structures/stack/stack.js +50 -0
- package/dist/data-structures/stack/stack.js.map +1 -1
- package/dist/data-structures/tree/index.d.ts +1 -0
- package/dist/data-structures/tree/tree.d.ts +14 -0
- package/dist/data-structures/tree/tree.js +1 -0
- package/dist/data-structures/tree/tree.js.map +1 -1
- package/dist/data-structures/trie/index.d.ts +1 -0
- package/dist/data-structures/trie/trie.d.ts +61 -0
- package/dist/data-structures/trie/trie.js +36 -0
- package/dist/data-structures/trie/trie.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/interfaces/abstract-binary-tree.d.ts +7 -0
- package/dist/interfaces/abstract-graph.d.ts +5 -0
- package/dist/interfaces/avl-tree.d.ts +7 -0
- package/dist/interfaces/binary-tree.d.ts +6 -0
- package/dist/interfaces/bst.d.ts +6 -0
- package/dist/interfaces/directed-graph.d.ts +3 -0
- package/dist/interfaces/doubly-linked-list.d.ts +1 -0
- package/dist/interfaces/heap.d.ts +1 -0
- package/dist/interfaces/index.d.ts +15 -0
- package/dist/interfaces/navigator.d.ts +1 -0
- package/dist/interfaces/priority-queue.d.ts +1 -0
- package/dist/interfaces/rb-tree.d.ts +6 -0
- package/dist/interfaces/segment-tree.d.ts +1 -0
- package/dist/interfaces/singly-linked-list.d.ts +1 -0
- package/dist/interfaces/tree-multiset.d.ts +6 -0
- package/dist/interfaces/undirected-graph.d.ts +3 -0
- package/dist/types/data-structures/abstract-binary-tree.d.ts +34 -0
- package/dist/types/data-structures/abstract-binary-tree.js +6 -0
- package/dist/types/data-structures/abstract-binary-tree.js.map +1 -1
- package/dist/types/data-structures/abstract-graph.d.ts +11 -0
- package/dist/types/data-structures/avl-tree.d.ts +4 -0
- package/dist/types/data-structures/binary-tree.d.ts +4 -0
- package/dist/types/data-structures/bst.d.ts +13 -0
- package/dist/types/data-structures/directed-graph.d.ts +6 -0
- package/dist/types/data-structures/doubly-linked-list.d.ts +1 -0
- package/dist/types/data-structures/hash.d.ts +1 -0
- package/dist/types/data-structures/heap.d.ts +3 -0
- package/dist/types/data-structures/index.d.ts +16 -0
- package/dist/types/data-structures/map-graph.d.ts +1 -0
- package/dist/types/data-structures/navigator.d.ts +14 -0
- package/dist/types/data-structures/priority-queue.d.ts +7 -0
- package/dist/types/data-structures/rb-tree.d.ts +8 -0
- package/dist/types/data-structures/segment-tree.d.ts +1 -0
- package/dist/types/data-structures/singly-linked-list.d.ts +1 -0
- package/dist/types/data-structures/tree-multiset.d.ts +4 -0
- package/dist/types/helpers.d.ts +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/utils.d.ts +7 -0
- package/dist/types/utils/validate-type.d.ts +19 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/utils.d.ts +19 -0
- package/package.json +11 -7
- package/test/integration/avl-tree.test.ts +4 -4
- package/test/integration/bst.test.ts +8 -8
- package/test/unit/data-structures/graph/directed-graph.test.ts +5 -5
- package/test/unit/data-structures/graph/overall.test.ts +2 -2
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +1 -1
- package/test/unit/data-structures/graph/index.ts +0 -2
- package/test/unit/data-structures/linked-list/index.ts +0 -4
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DoublyLinkedList = exports.DoublyLinkedListNode = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* data-structure-typed
|
|
6
|
+
*
|
|
7
|
+
* @author Tyler Zeng
|
|
8
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
9
|
+
* @license MIT License
|
|
10
|
+
*/
|
|
4
11
|
class DoublyLinkedListNode {
|
|
12
|
+
/**
|
|
13
|
+
* The constructor function initializes the value, next, and previous properties of an object.
|
|
14
|
+
* @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
|
|
15
|
+
* is defined as a generic type "E".
|
|
16
|
+
*/
|
|
5
17
|
constructor(val) {
|
|
6
18
|
this._val = val;
|
|
7
19
|
this._next = null;
|
|
@@ -28,6 +40,9 @@ class DoublyLinkedListNode {
|
|
|
28
40
|
}
|
|
29
41
|
exports.DoublyLinkedListNode = DoublyLinkedListNode;
|
|
30
42
|
class DoublyLinkedList {
|
|
43
|
+
/**
|
|
44
|
+
* The constructor initializes the linked list with an empty head, tail, and length.
|
|
45
|
+
*/
|
|
31
46
|
constructor() {
|
|
32
47
|
this._head = null;
|
|
33
48
|
this._tail = null;
|
|
@@ -48,6 +63,12 @@ class DoublyLinkedList {
|
|
|
48
63
|
get length() {
|
|
49
64
|
return this._length;
|
|
50
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
|
|
68
|
+
* given array.
|
|
69
|
+
* @param {E[]} data - The `data` parameter is an array of elements of type `E`.
|
|
70
|
+
* @returns The `fromArray` function returns a DoublyLinkedList object.
|
|
71
|
+
*/
|
|
51
72
|
static fromArray(data) {
|
|
52
73
|
const doublyLinkedList = new DoublyLinkedList();
|
|
53
74
|
for (const item of data) {
|
|
@@ -55,6 +76,10 @@ class DoublyLinkedList {
|
|
|
55
76
|
}
|
|
56
77
|
return doublyLinkedList;
|
|
57
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* The push function adds a new node with the given value to the end of the doubly linked list.
|
|
81
|
+
* @param {E} val - The value to be added to the linked list.
|
|
82
|
+
*/
|
|
58
83
|
push(val) {
|
|
59
84
|
const newNode = new DoublyLinkedListNode(val);
|
|
60
85
|
if (!this.head) {
|
|
@@ -68,9 +93,18 @@ class DoublyLinkedList {
|
|
|
68
93
|
}
|
|
69
94
|
this._length++;
|
|
70
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* The addLast function adds a new node with the given value to the end of the doubly linked list.
|
|
98
|
+
* @param {E} val - The value to be added to the linked list.
|
|
99
|
+
*/
|
|
71
100
|
addLast(val) {
|
|
72
101
|
this.push(val);
|
|
73
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* The `pop()` function removes and returns the value of the last node in a doubly linked list.
|
|
105
|
+
* @returns The method is returning the value of the removed node (removedNode.val) if the list is not empty. If the
|
|
106
|
+
* list is empty, it returns null.
|
|
107
|
+
*/
|
|
74
108
|
pop() {
|
|
75
109
|
if (!this.tail)
|
|
76
110
|
return undefined;
|
|
@@ -86,9 +120,19 @@ class DoublyLinkedList {
|
|
|
86
120
|
this._length--;
|
|
87
121
|
return removedNode.val;
|
|
88
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* The `pollLast()` function removes and returns the value of the last node in a doubly linked list.
|
|
125
|
+
* @returns The method is returning the value of the removed node (removedNode.val) if the list is not empty. If the
|
|
126
|
+
* list is empty, it returns null.
|
|
127
|
+
*/
|
|
89
128
|
pollLast() {
|
|
90
129
|
return this.pop();
|
|
91
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* The `shift()` function removes and returns the value of the first node in a doubly linked list.
|
|
133
|
+
* @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
|
|
134
|
+
* list.
|
|
135
|
+
*/
|
|
92
136
|
shift() {
|
|
93
137
|
if (!this.head)
|
|
94
138
|
return undefined;
|
|
@@ -104,9 +148,19 @@ class DoublyLinkedList {
|
|
|
104
148
|
this._length--;
|
|
105
149
|
return removedNode.val;
|
|
106
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* The `pollFirst()` function removes and returns the value of the first node in a doubly linked list.
|
|
153
|
+
* @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
|
|
154
|
+
* list.
|
|
155
|
+
*/
|
|
107
156
|
pollFirst() {
|
|
108
157
|
return this.shift();
|
|
109
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* The unshift function adds a new node with the given value to the beginning of a doubly linked list.
|
|
161
|
+
* @param {E} val - The `val` parameter represents the value of the new node that will be added to the beginning of the
|
|
162
|
+
* doubly linked list.
|
|
163
|
+
*/
|
|
110
164
|
unshift(val) {
|
|
111
165
|
const newNode = new DoublyLinkedListNode(val);
|
|
112
166
|
if (!this.head) {
|
|
@@ -120,13 +174,26 @@ class DoublyLinkedList {
|
|
|
120
174
|
}
|
|
121
175
|
this._length++;
|
|
122
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* The addFirst function adds a new node with the given value to the beginning of a doubly linked list.
|
|
179
|
+
* @param {E} val - The `val` parameter represents the value of the new node that will be added to the beginning of the
|
|
180
|
+
* doubly linked list.
|
|
181
|
+
*/
|
|
123
182
|
addFirst(val) {
|
|
124
183
|
this.unshift(val);
|
|
125
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* The `peekFirst` function returns the first node in a doubly linked list, or null if the list is empty.
|
|
187
|
+
* @returns The method `peekFirst()` returns the first node of the doubly linked list, or `null` if the list is empty.
|
|
188
|
+
*/
|
|
126
189
|
peekFirst() {
|
|
127
190
|
var _a;
|
|
128
191
|
return (_a = this.head) === null || _a === void 0 ? void 0 : _a.val;
|
|
129
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* The `peekLast` function returns the last node in a doubly linked list, or null if the list is empty.
|
|
195
|
+
* @returns The method `peekLast()` returns the last node of the doubly linked list, or `null` if the list is empty.
|
|
196
|
+
*/
|
|
130
197
|
peekLast() {
|
|
131
198
|
var _a;
|
|
132
199
|
return (_a = this.tail) === null || _a === void 0 ? void 0 : _a.val;
|
|
@@ -134,6 +201,13 @@ class DoublyLinkedList {
|
|
|
134
201
|
get size() {
|
|
135
202
|
return this.length;
|
|
136
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* The `getAt` function returns the value at a specified index in a linked list, or null if the index is out of bounds.
|
|
206
|
+
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
207
|
+
* retrieve from the list.
|
|
208
|
+
* @returns The method is returning the value at the specified index in the linked list. If the index is out of bounds
|
|
209
|
+
* or the linked list is empty, it will return null.
|
|
210
|
+
*/
|
|
137
211
|
getAt(index) {
|
|
138
212
|
if (index < 0 || index >= this.length)
|
|
139
213
|
return undefined;
|
|
@@ -143,6 +217,14 @@ class DoublyLinkedList {
|
|
|
143
217
|
}
|
|
144
218
|
return current.val;
|
|
145
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* The function `getNodeAt` returns the node at a given index in a doubly linked list, or null if the index is out of
|
|
222
|
+
* range.
|
|
223
|
+
* @param {number} index - The `index` parameter is a number that represents the position of the node we want to
|
|
224
|
+
* retrieve from the doubly linked list. It indicates the zero-based index of the node we want to access.
|
|
225
|
+
* @returns The method `getNodeAt(index: number)` returns a `DoublyLinkedListNode<E>` object if the index is within the
|
|
226
|
+
* valid range of the linked list, otherwise it returns `null`.
|
|
227
|
+
*/
|
|
146
228
|
getNodeAt(index) {
|
|
147
229
|
if (index < 0 || index >= this.length)
|
|
148
230
|
return null;
|
|
@@ -152,6 +234,13 @@ class DoublyLinkedList {
|
|
|
152
234
|
}
|
|
153
235
|
return current;
|
|
154
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
|
|
239
|
+
* node if found, otherwise it returns null.
|
|
240
|
+
* @param {E} val - The `val` parameter is the value that we want to search for in the doubly linked list.
|
|
241
|
+
* @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<E>` if a node with the specified value `val`
|
|
242
|
+
* is found in the linked list. If no such node is found, it returns `null`.
|
|
243
|
+
*/
|
|
155
244
|
findNode(val) {
|
|
156
245
|
let current = this.head;
|
|
157
246
|
while (current) {
|
|
@@ -162,6 +251,15 @@ class DoublyLinkedList {
|
|
|
162
251
|
}
|
|
163
252
|
return null;
|
|
164
253
|
}
|
|
254
|
+
/**
|
|
255
|
+
* The `insert` function inserts a value at a specified index in a doubly linked list.
|
|
256
|
+
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
257
|
+
* DoublyLinkedList. It is of type number.
|
|
258
|
+
* @param {E} val - The `val` parameter represents the value that you want to insert into the Doubly Linked List at the
|
|
259
|
+
* specified index.
|
|
260
|
+
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
|
|
261
|
+
* if the index is out of bounds.
|
|
262
|
+
*/
|
|
165
263
|
insertAt(index, val) {
|
|
166
264
|
if (index < 0 || index > this.length)
|
|
167
265
|
return false;
|
|
@@ -183,6 +281,13 @@ class DoublyLinkedList {
|
|
|
183
281
|
this._length++;
|
|
184
282
|
return true;
|
|
185
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
|
|
286
|
+
* @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
|
|
287
|
+
* data structure. It is of type number.
|
|
288
|
+
* @returns The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of
|
|
289
|
+
* bounds.
|
|
290
|
+
*/
|
|
186
291
|
deleteAt(index) {
|
|
187
292
|
if (index < 0 || index >= this.length)
|
|
188
293
|
return undefined;
|
|
@@ -198,6 +303,13 @@ class DoublyLinkedList {
|
|
|
198
303
|
this._length--;
|
|
199
304
|
return removedNode.val;
|
|
200
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* The `delete` function removes a node from a doubly linked list based on either the node itself or its value.
|
|
308
|
+
* @param {E | DoublyLinkedListNode<E>} valOrNode - The `valOrNode` parameter can accept either a value of type `E` or
|
|
309
|
+
* a `DoublyLinkedListNode<E>` object.
|
|
310
|
+
* @returns The `delete` method returns a boolean value. It returns `true` if the value or node was successfully
|
|
311
|
+
* deleted from the doubly linked list, and `false` if the value or node was not found in the list.
|
|
312
|
+
*/
|
|
201
313
|
delete(valOrNode) {
|
|
202
314
|
let node;
|
|
203
315
|
if (valOrNode instanceof DoublyLinkedListNode) {
|
|
@@ -224,6 +336,10 @@ class DoublyLinkedList {
|
|
|
224
336
|
}
|
|
225
337
|
return false;
|
|
226
338
|
}
|
|
339
|
+
/**
|
|
340
|
+
* The `toArray` function converts a linked list into an array.
|
|
341
|
+
* @returns The `toArray()` method is returning an array of type `E[]`.
|
|
342
|
+
*/
|
|
227
343
|
toArray() {
|
|
228
344
|
const array = [];
|
|
229
345
|
let current = this.head;
|
|
@@ -233,14 +349,28 @@ class DoublyLinkedList {
|
|
|
233
349
|
}
|
|
234
350
|
return array;
|
|
235
351
|
}
|
|
352
|
+
/**
|
|
353
|
+
* The function checks if a variable has a length greater than zero and returns a boolean value.
|
|
354
|
+
* @returns A boolean value is being returned.
|
|
355
|
+
*/
|
|
236
356
|
isEmpty() {
|
|
237
357
|
return this.length === 0;
|
|
238
358
|
}
|
|
359
|
+
/**
|
|
360
|
+
* The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively.
|
|
361
|
+
*/
|
|
239
362
|
clear() {
|
|
240
363
|
this._head = null;
|
|
241
364
|
this._tail = null;
|
|
242
365
|
this._length = 0;
|
|
243
366
|
}
|
|
367
|
+
/**
|
|
368
|
+
* The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
|
|
369
|
+
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
370
|
+
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
|
|
371
|
+
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
|
|
372
|
+
* the callback function. If no element satisfies the condition, it returns `null`.
|
|
373
|
+
*/
|
|
244
374
|
find(callback) {
|
|
245
375
|
let current = this.head;
|
|
246
376
|
while (current) {
|
|
@@ -251,6 +381,13 @@ class DoublyLinkedList {
|
|
|
251
381
|
}
|
|
252
382
|
return null;
|
|
253
383
|
}
|
|
384
|
+
/**
|
|
385
|
+
* The function returns the index of the first occurrence of a given value in a linked list.
|
|
386
|
+
* @param {E} val - The parameter `val` is of type `E`, which means it can be any data type. It represents the value
|
|
387
|
+
* that we are searching for in the linked list.
|
|
388
|
+
* @returns The method `indexOf` returns the index of the first occurrence of the specified value `val` in the linked
|
|
389
|
+
* list. If the value is not found, it returns -1.
|
|
390
|
+
*/
|
|
254
391
|
indexOf(val) {
|
|
255
392
|
let index = 0;
|
|
256
393
|
let current = this.head;
|
|
@@ -263,6 +400,14 @@ class DoublyLinkedList {
|
|
|
263
400
|
}
|
|
264
401
|
return -1;
|
|
265
402
|
}
|
|
403
|
+
/**
|
|
404
|
+
* The `findLast` function iterates through a linked list from the last node to the first node and returns the last
|
|
405
|
+
* value that satisfies the given callback function, or null if no value satisfies the callback.
|
|
406
|
+
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
407
|
+
* function is used to determine whether a given value satisfies a certain condition.
|
|
408
|
+
* @returns The method `findLast` returns the last value in the linked list that satisfies the condition specified by
|
|
409
|
+
* the callback function. If no value satisfies the condition, it returns `null`.
|
|
410
|
+
*/
|
|
266
411
|
findLast(callback) {
|
|
267
412
|
let current = this.tail;
|
|
268
413
|
while (current) {
|
|
@@ -273,6 +418,10 @@ class DoublyLinkedList {
|
|
|
273
418
|
}
|
|
274
419
|
return null;
|
|
275
420
|
}
|
|
421
|
+
/**
|
|
422
|
+
* The `toArrayReverse` function converts a doubly linked list into an array in reverse order.
|
|
423
|
+
* @returns The `toArrayReverse()` function returns an array of type `E[]`.
|
|
424
|
+
*/
|
|
276
425
|
toArrayReverse() {
|
|
277
426
|
const array = [];
|
|
278
427
|
let current = this.tail;
|
|
@@ -282,6 +431,9 @@ class DoublyLinkedList {
|
|
|
282
431
|
}
|
|
283
432
|
return array;
|
|
284
433
|
}
|
|
434
|
+
/**
|
|
435
|
+
* The `reverse` function reverses the order of the elements in a doubly linked list.
|
|
436
|
+
*/
|
|
285
437
|
reverse() {
|
|
286
438
|
let current = this.head;
|
|
287
439
|
[this.head, this.tail] = [this.tail, this.head];
|
|
@@ -291,6 +443,12 @@ class DoublyLinkedList {
|
|
|
291
443
|
current = next;
|
|
292
444
|
}
|
|
293
445
|
}
|
|
446
|
+
/**
|
|
447
|
+
* The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
|
|
448
|
+
* @param callback - The callback parameter is a function that takes two arguments: val and index. The val argument
|
|
449
|
+
* represents the value of the current node in the linked list, and the index argument represents the index of the
|
|
450
|
+
* current node in the linked list.
|
|
451
|
+
*/
|
|
294
452
|
forEach(callback) {
|
|
295
453
|
let current = this.head;
|
|
296
454
|
let index = 0;
|
|
@@ -300,6 +458,14 @@ class DoublyLinkedList {
|
|
|
300
458
|
index++;
|
|
301
459
|
}
|
|
302
460
|
}
|
|
461
|
+
/**
|
|
462
|
+
* The `map` function takes a callback function and applies it to each element in the DoublyLinkedList, returning a new
|
|
463
|
+
* DoublyLinkedList with the transformed values.
|
|
464
|
+
* @param callback - The callback parameter is a function that takes a value of type E (the type of values stored in
|
|
465
|
+
* the original DoublyLinkedList) and returns a value of type U (the type of values that will be stored in the mapped
|
|
466
|
+
* DoublyLinkedList).
|
|
467
|
+
* @returns The `map` function is returning a new instance of `DoublyLinkedList<U>` that contains the mapped values.
|
|
468
|
+
*/
|
|
303
469
|
map(callback) {
|
|
304
470
|
const mappedList = new DoublyLinkedList();
|
|
305
471
|
let current = this.head;
|
|
@@ -309,6 +475,13 @@ class DoublyLinkedList {
|
|
|
309
475
|
}
|
|
310
476
|
return mappedList;
|
|
311
477
|
}
|
|
478
|
+
/**
|
|
479
|
+
* The `filter` function iterates through a DoublyLinkedList and returns a new DoublyLinkedList containing only the
|
|
480
|
+
* elements that satisfy the given callback function.
|
|
481
|
+
* @param callback - The `callback` parameter is a function that takes a value of type `E` and returns a boolean value.
|
|
482
|
+
* It is used to determine whether a value should be included in the filtered list or not.
|
|
483
|
+
* @returns The filtered list, which is an instance of the DoublyLinkedList class.
|
|
484
|
+
*/
|
|
312
485
|
filter(callback) {
|
|
313
486
|
const filteredList = new DoublyLinkedList();
|
|
314
487
|
let current = this.head;
|
|
@@ -320,6 +493,16 @@ class DoublyLinkedList {
|
|
|
320
493
|
}
|
|
321
494
|
return filteredList;
|
|
322
495
|
}
|
|
496
|
+
/**
|
|
497
|
+
* The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
|
|
498
|
+
* single value.
|
|
499
|
+
* @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `val`. It is
|
|
500
|
+
* used to perform a specific operation on each element of the linked list.
|
|
501
|
+
* @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
|
|
502
|
+
* point for the reduction operation.
|
|
503
|
+
* @returns The `reduce` method is returning the final value of the accumulator after iterating through all the
|
|
504
|
+
* elements in the linked list.
|
|
505
|
+
*/
|
|
323
506
|
reduce(callback, initialValue) {
|
|
324
507
|
let accumulator = initialValue;
|
|
325
508
|
let current = this.head;
|
|
@@ -329,6 +512,15 @@ class DoublyLinkedList {
|
|
|
329
512
|
}
|
|
330
513
|
return accumulator;
|
|
331
514
|
}
|
|
515
|
+
/**
|
|
516
|
+
* The `insertAfter` function inserts a new node with a given value after an existing node in a doubly linked list.
|
|
517
|
+
* @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
|
|
518
|
+
* after which the new value will be inserted. It can be either the value of the existing node or the existing node
|
|
519
|
+
* itself.
|
|
520
|
+
* @param {E} newValue - The value that you want to insert into the doubly linked list.
|
|
521
|
+
* @returns The method returns a boolean value. It returns true if the insertion is successful, and false if the
|
|
522
|
+
* existing value or node is not found in the doubly linked list.
|
|
523
|
+
*/
|
|
332
524
|
insertAfter(existingValueOrNode, newValue) {
|
|
333
525
|
let existingNode;
|
|
334
526
|
if (existingValueOrNode instanceof DoublyLinkedListNode) {
|
|
@@ -353,6 +545,16 @@ class DoublyLinkedList {
|
|
|
353
545
|
}
|
|
354
546
|
return false;
|
|
355
547
|
}
|
|
548
|
+
/**
|
|
549
|
+
* The `insertBefore` function inserts a new value before an existing value or node in a doubly linked list.
|
|
550
|
+
* @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
|
|
551
|
+
* before which the new value will be inserted. It can be either the value of the existing node or the existing node
|
|
552
|
+
* itself.
|
|
553
|
+
* @param {E} newValue - The `newValue` parameter represents the value that you want to insert into the doubly linked
|
|
554
|
+
* list.
|
|
555
|
+
* @returns The method returns a boolean value. It returns `true` if the insertion is successful, and `false` if the
|
|
556
|
+
* insertion fails.
|
|
557
|
+
*/
|
|
356
558
|
insertBefore(existingValueOrNode, newValue) {
|
|
357
559
|
let existingNode;
|
|
358
560
|
if (existingValueOrNode instanceof DoublyLinkedListNode) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doubly-linked-list.js","sourceRoot":"","sources":["../../../src/data-structures/linked-list/doubly-linked-list.ts"],"names":[],"mappings":";;;AAOA,MAAa,oBAAoB;IAM/B,YAAY,GAAM;QAChB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAID,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,IAAI,GAAG,CAAC,KAAQ;QACd,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;IACpB,CAAC;IAID,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,IAAI,IAAI,CAAC,KAAqC;QAC5C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAID,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,IAAI,IAAI,CA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AAY,CAAC,IAAI,GAAG,OAAO,CAAC;YAC5B,IAAI,YAAY,KAAK,IAAI,CAAC,IAAI,EAAE;gBAC9B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;aACrB;YACD,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,OAAO,IAAI,CAAC;SACb;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAKD;;;;;;;;;OASG;IACH,YAAY,CAAC,mBAAgD,EAAE,QAAW;QACxE,IAAI,YAAY,CAAC;QAEjB,IAAI,mBAAmB,YAAY,oBAAoB,EAAE;YACvD,YAAY,GAAG,mBAAmB,CAAC;SACpC;aAAM;YACL,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC;SACnD;QAED,IAAI,YAAY,EAAE;YAChB,MAAM,OAAO,GAAG,IAAI,oBAAoB,CAAC,QAAQ,CAAC,CAAC;YACnD,OAAO,CAAC,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC;YACjC,IAAI,YAAY,CAAC,IAAI,EAAE;gBACrB,YAAY,CAAC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;aAClC;YACD,OAAO,CAAC,IAAI,GAAG,YAAY,CAAC;YAC5B,YAAY,CAAC,IAAI,GAAG,OAAO,CAAC;YAC5B,IAAI,YAAY,KAAK,IAAI,CAAC,IAAI,EAAE;gBAC9B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;aACrB;YACD,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,OAAO,IAAI,CAAC;SACb;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAzkBD,4CAykBC"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
7
|
+
*/
|
|
8
|
+
export declare class SinglyLinkedListNode<E = any> {
|
|
9
|
+
/**
|
|
10
|
+
* The constructor function initializes an instance of a class with a given value and sets the next property to null.
|
|
11
|
+
* @param {E} val - The "val" parameter is of type E, 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: E);
|
|
15
|
+
private _val;
|
|
16
|
+
get val(): E;
|
|
17
|
+
set val(value: E);
|
|
18
|
+
private _next;
|
|
19
|
+
get next(): SinglyLinkedListNode<E> | null;
|
|
20
|
+
set next(value: SinglyLinkedListNode<E> | null);
|
|
21
|
+
}
|
|
22
|
+
export declare class SinglyLinkedList<E = 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<E> | null;
|
|
29
|
+
set head(value: SinglyLinkedListNode<E> | null);
|
|
30
|
+
private _tail;
|
|
31
|
+
get tail(): SinglyLinkedListNode<E> | null;
|
|
32
|
+
set tail(value: SinglyLinkedListNode<E> | null);
|
|
33
|
+
private _length;
|
|
34
|
+
get length(): number;
|
|
35
|
+
/**
|
|
36
|
+
* The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
|
|
37
|
+
* array.
|
|
38
|
+
* @param {E[]} data - The `data` parameter is an array of elements of type `E`.
|
|
39
|
+
* @returns The `fromArray` function returns a `SinglyLinkedList` object.
|
|
40
|
+
*/
|
|
41
|
+
static fromArray<E>(data: E[]): SinglyLinkedList<E>;
|
|
42
|
+
getLength(): number;
|
|
43
|
+
/**
|
|
44
|
+
* The `push` function adds a new node with the given data to the end of a singly linked list.
|
|
45
|
+
* @param {E} data - The "data" parameter represents the value that you want to add to the linked list. It can be of
|
|
46
|
+
* any type (E) as specified in the generic type declaration of the class or function.
|
|
47
|
+
*/
|
|
48
|
+
push(data: E): void;
|
|
49
|
+
/**
|
|
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`.
|
|
54
|
+
*/
|
|
55
|
+
pop(): E | undefined;
|
|
56
|
+
/**
|
|
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.
|
|
59
|
+
*/
|
|
60
|
+
shift(): E | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* The unshift function adds a new node with the given value to the beginning of a singly linked list.
|
|
63
|
+
* @param {E} val - The parameter "val" represents the value of the new node that will be added to the beginning of the
|
|
64
|
+
* linked list.
|
|
65
|
+
*/
|
|
66
|
+
unshift(val: E): void;
|
|
67
|
+
/**
|
|
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): E | null` returns the value at the specified index in the linked list, or
|
|
72
|
+
* `null` if the index is out of bounds.
|
|
73
|
+
*/
|
|
74
|
+
getAt(index: number): E | undefined;
|
|
75
|
+
/**
|
|
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<E>` object if the node at the
|
|
80
|
+
* specified index exists, or `null` if the index is out of bounds.
|
|
81
|
+
*/
|
|
82
|
+
getNodeAt(index: number): SinglyLinkedListNode<E> | null;
|
|
83
|
+
/**
|
|
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.
|
|
89
|
+
*/
|
|
90
|
+
deleteAt(index: number): E | undefined;
|
|
91
|
+
delete(valueOrNode: E): boolean;
|
|
92
|
+
delete(valueOrNode: SinglyLinkedListNode<E>): boolean;
|
|
93
|
+
/**
|
|
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 {E} 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.
|
|
101
|
+
*/
|
|
102
|
+
insertAt(index: number, val: E): boolean;
|
|
103
|
+
/**
|
|
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.
|
|
107
|
+
*/
|
|
108
|
+
isEmpty(): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively.
|
|
111
|
+
*/
|
|
112
|
+
clear(): void;
|
|
113
|
+
/**
|
|
114
|
+
* The `toArray` function converts a linked list into an array.
|
|
115
|
+
* @returns The `toArray()` method is returning an array of type `E[]`.
|
|
116
|
+
*/
|
|
117
|
+
toArray(): E[];
|
|
118
|
+
/**
|
|
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.
|
|
121
|
+
*/
|
|
122
|
+
reverse(): void;
|
|
123
|
+
/**
|
|
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 E 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`.
|
|
129
|
+
*/
|
|
130
|
+
find(callback: (val: E) => boolean): E | null;
|
|
131
|
+
/**
|
|
132
|
+
* The `indexOf` function returns the index of the first occurrence of a given value in a linked list.
|
|
133
|
+
* @param {E} 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.
|
|
136
|
+
*/
|
|
137
|
+
indexOf(value: E): number;
|
|
138
|
+
/**
|
|
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 {E} value - The value parameter is the value that we want to search for in the linked list.
|
|
142
|
+
* @returns a `SinglyLinkedListNode<E>` 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`.
|
|
144
|
+
*/
|
|
145
|
+
findNode(value: E): SinglyLinkedListNode<E> | null;
|
|
146
|
+
insertBefore(existingValue: E, newValue: E): boolean;
|
|
147
|
+
insertBefore(existingValue: SinglyLinkedListNode<E>, newValue: E): boolean;
|
|
148
|
+
insertAfter(existingValueOrNode: E, newValue: E): boolean;
|
|
149
|
+
insertAfter(existingValueOrNode: SinglyLinkedListNode<E>, newValue: E): boolean;
|
|
150
|
+
/**
|
|
151
|
+
* The function counts the number of occurrences of a given value in a linked list.
|
|
152
|
+
* @param {E} 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.
|
|
154
|
+
*/
|
|
155
|
+
countOccurrences(value: E): number;
|
|
156
|
+
[Symbol.iterator](): Generator<E, void, unknown>;
|
|
157
|
+
}
|