data-structure-typed 1.50.4 → 1.50.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/CHANGELOG.md +1 -1
- package/README.md +116 -55
- package/SPECIFICATION.md +2 -2
- package/SPECIFICATION_zh-CN.md +81 -0
- package/{SPONSOR-zh-CN.md → SPONSOR_zh-CN.md} +1 -1
- package/benchmark/report.html +24 -24
- package/benchmark/report.json +242 -242
- package/dist/cjs/data-structures/base/iterable-base.d.ts +10 -8
- package/dist/cjs/data-structures/base/iterable-base.js +8 -12
- package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -0
- package/dist/cjs/data-structures/graph/abstract-graph.js +3 -0
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +14 -76
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +16 -86
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +27 -69
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +35 -79
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +0 -53
- package/dist/cjs/data-structures/queue/deque.js +0 -61
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +0 -70
- package/dist/cjs/data-structures/queue/queue.js +0 -87
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/mjs/data-structures/base/iterable-base.d.ts +10 -8
- package/dist/mjs/data-structures/base/iterable-base.js +8 -12
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -0
- package/dist/mjs/data-structures/graph/abstract-graph.js +3 -0
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +14 -76
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +16 -86
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +27 -69
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +33 -79
- package/dist/mjs/data-structures/queue/deque.d.ts +0 -53
- package/dist/mjs/data-structures/queue/deque.js +0 -61
- package/dist/mjs/data-structures/queue/queue.d.ts +0 -70
- package/dist/mjs/data-structures/queue/queue.js +0 -86
- package/dist/umd/data-structure-typed.js +62 -325
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/base/iterable-base.ts +14 -10
- package/src/data-structures/graph/abstract-graph.ts +4 -0
- package/src/data-structures/heap/heap.ts +1 -1
- package/src/data-structures/linked-list/doubly-linked-list.ts +16 -94
- package/src/data-structures/linked-list/singly-linked-list.ts +35 -87
- package/src/data-structures/queue/deque.ts +0 -67
- package/src/data-structures/queue/queue.ts +0 -98
- package/test/performance/data-structures/binary-tree/avl-tree.test.ts +3 -3
- package/test/performance/data-structures/binary-tree/binary-tree-overall.test.ts +3 -3
- package/test/performance/data-structures/hash/hash-map.test.ts +6 -6
- package/test/performance/data-structures/heap/heap.test.ts +14 -14
- package/test/performance/data-structures/priority-queue/priority-queue.test.ts +11 -6
- package/test/performance/data-structures/queue/deque.test.ts +8 -8
- package/test/performance/data-structures/queue/queue.test.ts +5 -12
- package/test/performance/reportor.ts +43 -1
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +6 -6
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +10 -10
- package/test/unit/data-structures/linked-list/skip-list.test.ts +4 -4
- package/test/unit/data-structures/queue/deque.test.ts +26 -26
- package/test/unit/data-structures/queue/queue.test.ts +20 -20
|
@@ -60,6 +60,18 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
60
60
|
* @returns The method is returning either a SinglyLinkedListNode object or undefined.
|
|
61
61
|
*/
|
|
62
62
|
get tail(): SinglyLinkedListNode<E> | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* The above function returns the value of the first element in a linked list, or undefined if the
|
|
65
|
+
* list is empty.
|
|
66
|
+
* @returns The value of the first node in the linked list, or undefined if the linked list is empty.
|
|
67
|
+
*/
|
|
68
|
+
get first(): E | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* The function returns the value of the last element in a linked list, or undefined if the list is
|
|
71
|
+
* empty.
|
|
72
|
+
* @returns The value of the last node in the linked list, or undefined if the linked list is empty.
|
|
73
|
+
*/
|
|
74
|
+
get last(): E | undefined;
|
|
63
75
|
protected _size: number;
|
|
64
76
|
/**
|
|
65
77
|
* The function returns the size of an object.
|
|
@@ -82,21 +94,6 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
82
94
|
* @returns The `fromArray` function returns a `SinglyLinkedList` object.
|
|
83
95
|
*/
|
|
84
96
|
static fromArray<E>(data: E[]): SinglyLinkedList<E>;
|
|
85
|
-
/**
|
|
86
|
-
* Time Complexity: O(1)
|
|
87
|
-
* Space Complexity: O(1)
|
|
88
|
-
* Constant time, as it involves basic pointer adjustments.
|
|
89
|
-
* Constant space, as it only creates a new node.
|
|
90
|
-
*/
|
|
91
|
-
/**
|
|
92
|
-
* Time Complexity: O(1)
|
|
93
|
-
* Space Complexity: O(1)
|
|
94
|
-
*
|
|
95
|
-
* The `push` function adds a new node with the given value to the end of a singly linked list.
|
|
96
|
-
* @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
|
|
97
|
-
* any type (E) as specified in the generic type declaration of the class or function.
|
|
98
|
-
*/
|
|
99
|
-
push(value: E): boolean;
|
|
100
97
|
/**
|
|
101
98
|
* Time Complexity: O(1)
|
|
102
99
|
* Space Complexity: O(1)
|
|
@@ -105,11 +102,12 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
105
102
|
* Time Complexity: O(1)
|
|
106
103
|
* Space Complexity: O(1)
|
|
107
104
|
*
|
|
108
|
-
* The
|
|
109
|
-
* @param {E}
|
|
110
|
-
*
|
|
105
|
+
* The push function adds a new element to the end of a singly linked list.
|
|
106
|
+
* @param {E} element - The "element" parameter represents the value of the element that you want to
|
|
107
|
+
* add to the linked list.
|
|
108
|
+
* @returns The `push` method is returning a boolean value, `true`.
|
|
111
109
|
*/
|
|
112
|
-
|
|
110
|
+
push(element: E): boolean;
|
|
113
111
|
/**
|
|
114
112
|
* Time Complexity: O(n)
|
|
115
113
|
* Space Complexity: O(1)
|
|
@@ -119,26 +117,11 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
119
117
|
* Time Complexity: O(n)
|
|
120
118
|
* Space Complexity: O(1)
|
|
121
119
|
*
|
|
122
|
-
* The `pop
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
* the linked list is empty, it returns `undefined`.
|
|
120
|
+
* The `pop` function removes and returns the value of the last element in a linked list.
|
|
121
|
+
* @returns The method is returning the value of the element that is being popped from the end of the
|
|
122
|
+
* list.
|
|
126
123
|
*/
|
|
127
124
|
pop(): E | undefined;
|
|
128
|
-
/**
|
|
129
|
-
* Time Complexity: O(n)
|
|
130
|
-
* Space Complexity: O(1)
|
|
131
|
-
*/
|
|
132
|
-
/**
|
|
133
|
-
* Time Complexity: O(n)
|
|
134
|
-
* Space Complexity: O(1)
|
|
135
|
-
*
|
|
136
|
-
* The `pollLast()` function removes and returns the value of the last element in a linked list, updating the head and tail
|
|
137
|
-
* pointers accordingly.
|
|
138
|
-
* @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
|
|
139
|
-
* the linked list is empty, it returns `undefined`.
|
|
140
|
-
*/
|
|
141
|
-
pollLast(): E | undefined;
|
|
142
125
|
/**
|
|
143
126
|
* Time Complexity: O(1)
|
|
144
127
|
* Space Complexity: O(1)
|
|
@@ -147,8 +130,8 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
147
130
|
* Time Complexity: O(1)
|
|
148
131
|
* Space Complexity: O(1)
|
|
149
132
|
*
|
|
150
|
-
* The `shift()` function removes and returns the value of the first
|
|
151
|
-
* @returns The value of the
|
|
133
|
+
* The `shift()` function removes and returns the value of the first element in a linked list.
|
|
134
|
+
* @returns The value of the removed node.
|
|
152
135
|
*/
|
|
153
136
|
shift(): E | undefined;
|
|
154
137
|
/**
|
|
@@ -159,40 +142,15 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
159
142
|
* Time Complexity: O(1)
|
|
160
143
|
* Space Complexity: O(1)
|
|
161
144
|
*
|
|
162
|
-
* The
|
|
163
|
-
* @
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Time Complexity: O(1)
|
|
168
|
-
* Space Complexity: O(1)
|
|
169
|
-
*/
|
|
170
|
-
/**
|
|
171
|
-
* Time Complexity: O(1)
|
|
172
|
-
* Space Complexity: O(1)
|
|
173
|
-
*
|
|
174
|
-
* The unshift function adds a new node with the given value to the beginning of a singly linked list.
|
|
175
|
-
* @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
|
|
176
|
-
* linked list.
|
|
177
|
-
*/
|
|
178
|
-
unshift(value: E): boolean;
|
|
179
|
-
/**
|
|
180
|
-
* Time Complexity: O(1)
|
|
181
|
-
* Space Complexity: O(1)
|
|
182
|
-
*/
|
|
183
|
-
/**
|
|
184
|
-
* Time Complexity: O(1)
|
|
185
|
-
* Space Complexity: O(1)
|
|
186
|
-
*
|
|
187
|
-
* The addFirst function adds a new node with the given value to the beginning of a singly linked list.
|
|
188
|
-
* @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
|
|
189
|
-
* linked list.
|
|
145
|
+
* The unshift function adds a new element to the beginning of a singly linked list.
|
|
146
|
+
* @param {E} element - The "element" parameter represents the value of the element that you want to
|
|
147
|
+
* add to the beginning of the singly linked list.
|
|
148
|
+
* @returns The `unshift` method is returning a boolean value, `true`.
|
|
190
149
|
*/
|
|
191
|
-
|
|
150
|
+
unshift(element: E): boolean;
|
|
192
151
|
/**
|
|
193
152
|
* Time Complexity: O(n)
|
|
194
153
|
* Space Complexity: O(1)
|
|
195
|
-
* Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
196
154
|
*/
|
|
197
155
|
/**
|
|
198
156
|
* Time Complexity: O(n)
|
|
@@ -73,6 +73,22 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
73
73
|
get tail() {
|
|
74
74
|
return this._tail;
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* The above function returns the value of the first element in a linked list, or undefined if the
|
|
78
|
+
* list is empty.
|
|
79
|
+
* @returns The value of the first node in the linked list, or undefined if the linked list is empty.
|
|
80
|
+
*/
|
|
81
|
+
get first() {
|
|
82
|
+
return this.head?.value;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The function returns the value of the last element in a linked list, or undefined if the list is
|
|
86
|
+
* empty.
|
|
87
|
+
* @returns The value of the last node in the linked list, or undefined if the linked list is empty.
|
|
88
|
+
*/
|
|
89
|
+
get last() {
|
|
90
|
+
return this.tail?.value;
|
|
91
|
+
}
|
|
76
92
|
_size = 0;
|
|
77
93
|
/**
|
|
78
94
|
* The function returns the size of an object.
|
|
@@ -106,19 +122,18 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
106
122
|
/**
|
|
107
123
|
* Time Complexity: O(1)
|
|
108
124
|
* Space Complexity: O(1)
|
|
109
|
-
* Constant time, as it involves basic pointer adjustments.
|
|
110
|
-
* Constant space, as it only creates a new node.
|
|
111
125
|
*/
|
|
112
126
|
/**
|
|
113
127
|
* Time Complexity: O(1)
|
|
114
128
|
* Space Complexity: O(1)
|
|
115
129
|
*
|
|
116
|
-
* The
|
|
117
|
-
* @param {E}
|
|
118
|
-
*
|
|
130
|
+
* The push function adds a new element to the end of a singly linked list.
|
|
131
|
+
* @param {E} element - The "element" parameter represents the value of the element that you want to
|
|
132
|
+
* add to the linked list.
|
|
133
|
+
* @returns The `push` method is returning a boolean value, `true`.
|
|
119
134
|
*/
|
|
120
|
-
push(
|
|
121
|
-
const newNode = new SinglyLinkedListNode(
|
|
135
|
+
push(element) {
|
|
136
|
+
const newNode = new SinglyLinkedListNode(element);
|
|
122
137
|
if (!this.head) {
|
|
123
138
|
this._head = newNode;
|
|
124
139
|
this._tail = newNode;
|
|
@@ -130,21 +145,6 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
130
145
|
this._size++;
|
|
131
146
|
return true;
|
|
132
147
|
}
|
|
133
|
-
/**
|
|
134
|
-
* Time Complexity: O(1)
|
|
135
|
-
* Space Complexity: O(1)
|
|
136
|
-
*/
|
|
137
|
-
/**
|
|
138
|
-
* Time Complexity: O(1)
|
|
139
|
-
* Space Complexity: O(1)
|
|
140
|
-
*
|
|
141
|
-
* The `push` function adds a new node with the given value to the end of a singly linked list.
|
|
142
|
-
* @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
|
|
143
|
-
* any type (E) as specified in the generic type declaration of the class or function.
|
|
144
|
-
*/
|
|
145
|
-
addLast(value) {
|
|
146
|
-
return this.push(value);
|
|
147
|
-
}
|
|
148
148
|
/**
|
|
149
149
|
* Time Complexity: O(n)
|
|
150
150
|
* Space Complexity: O(1)
|
|
@@ -154,10 +154,9 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
154
154
|
* Time Complexity: O(n)
|
|
155
155
|
* Space Complexity: O(1)
|
|
156
156
|
*
|
|
157
|
-
* The `pop
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
* the linked list is empty, it returns `undefined`.
|
|
157
|
+
* The `pop` function removes and returns the value of the last element in a linked list.
|
|
158
|
+
* @returns The method is returning the value of the element that is being popped from the end of the
|
|
159
|
+
* list.
|
|
161
160
|
*/
|
|
162
161
|
pop() {
|
|
163
162
|
if (!this.head)
|
|
@@ -179,22 +178,6 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
179
178
|
this._size--;
|
|
180
179
|
return value;
|
|
181
180
|
}
|
|
182
|
-
/**
|
|
183
|
-
* Time Complexity: O(n)
|
|
184
|
-
* Space Complexity: O(1)
|
|
185
|
-
*/
|
|
186
|
-
/**
|
|
187
|
-
* Time Complexity: O(n)
|
|
188
|
-
* Space Complexity: O(1)
|
|
189
|
-
*
|
|
190
|
-
* The `pollLast()` function removes and returns the value of the last element in a linked list, updating the head and tail
|
|
191
|
-
* pointers accordingly.
|
|
192
|
-
* @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
|
|
193
|
-
* the linked list is empty, it returns `undefined`.
|
|
194
|
-
*/
|
|
195
|
-
pollLast() {
|
|
196
|
-
return this.pop();
|
|
197
|
-
}
|
|
198
181
|
/**
|
|
199
182
|
* Time Complexity: O(1)
|
|
200
183
|
* Space Complexity: O(1)
|
|
@@ -203,8 +186,8 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
203
186
|
* Time Complexity: O(1)
|
|
204
187
|
* Space Complexity: O(1)
|
|
205
188
|
*
|
|
206
|
-
* The `shift()` function removes and returns the value of the first
|
|
207
|
-
* @returns The value of the
|
|
189
|
+
* The `shift()` function removes and returns the value of the first element in a linked list.
|
|
190
|
+
* @returns The value of the removed node.
|
|
208
191
|
*/
|
|
209
192
|
shift() {
|
|
210
193
|
if (!this.head)
|
|
@@ -222,26 +205,13 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
222
205
|
* Time Complexity: O(1)
|
|
223
206
|
* Space Complexity: O(1)
|
|
224
207
|
*
|
|
225
|
-
* The
|
|
226
|
-
* @
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
return this.shift();
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Time Complexity: O(1)
|
|
233
|
-
* Space Complexity: O(1)
|
|
234
|
-
*/
|
|
235
|
-
/**
|
|
236
|
-
* Time Complexity: O(1)
|
|
237
|
-
* Space Complexity: O(1)
|
|
238
|
-
*
|
|
239
|
-
* The unshift function adds a new node with the given value to the beginning of a singly linked list.
|
|
240
|
-
* @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
|
|
241
|
-
* linked list.
|
|
208
|
+
* The unshift function adds a new element to the beginning of a singly linked list.
|
|
209
|
+
* @param {E} element - The "element" parameter represents the value of the element that you want to
|
|
210
|
+
* add to the beginning of the singly linked list.
|
|
211
|
+
* @returns The `unshift` method is returning a boolean value, `true`.
|
|
242
212
|
*/
|
|
243
|
-
unshift(
|
|
244
|
-
const newNode = new SinglyLinkedListNode(
|
|
213
|
+
unshift(element) {
|
|
214
|
+
const newNode = new SinglyLinkedListNode(element);
|
|
245
215
|
if (!this.head) {
|
|
246
216
|
this._head = newNode;
|
|
247
217
|
this._tail = newNode;
|
|
@@ -253,25 +223,9 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
253
223
|
this._size++;
|
|
254
224
|
return true;
|
|
255
225
|
}
|
|
256
|
-
/**
|
|
257
|
-
* Time Complexity: O(1)
|
|
258
|
-
* Space Complexity: O(1)
|
|
259
|
-
*/
|
|
260
|
-
/**
|
|
261
|
-
* Time Complexity: O(1)
|
|
262
|
-
* Space Complexity: O(1)
|
|
263
|
-
*
|
|
264
|
-
* The addFirst function adds a new node with the given value to the beginning of a singly linked list.
|
|
265
|
-
* @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
|
|
266
|
-
* linked list.
|
|
267
|
-
*/
|
|
268
|
-
addFirst(value) {
|
|
269
|
-
return this.unshift(value);
|
|
270
|
-
}
|
|
271
226
|
/**
|
|
272
227
|
* Time Complexity: O(n)
|
|
273
228
|
* Space Complexity: O(1)
|
|
274
|
-
* Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
275
229
|
*/
|
|
276
230
|
/**
|
|
277
231
|
* Time Complexity: O(n)
|
|
@@ -432,59 +432,6 @@ export declare class Deque<E> extends IterableElementBase<E> {
|
|
|
432
432
|
* @returns a new Deque object with the mapped values.
|
|
433
433
|
*/
|
|
434
434
|
map<T>(callback: ElementCallback<E, T>, thisArg?: any): Deque<T>;
|
|
435
|
-
/**
|
|
436
|
-
* Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
|
|
437
|
-
* Space Complexity: O(n) - Due to potential resizing.
|
|
438
|
-
*/
|
|
439
|
-
/**
|
|
440
|
-
* Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
|
|
441
|
-
* Space Complexity: O(n) - Due to potential resizing.
|
|
442
|
-
*
|
|
443
|
-
* The addLast function adds an element to the end of an array.
|
|
444
|
-
* @param {E} element - The element parameter represents the element that you want to add to the end of the
|
|
445
|
-
* data structure.
|
|
446
|
-
*/
|
|
447
|
-
addLast(element: E): boolean;
|
|
448
|
-
/**
|
|
449
|
-
* Time Complexity: O(1)
|
|
450
|
-
* Space Complexity: O(1)
|
|
451
|
-
*/
|
|
452
|
-
/**
|
|
453
|
-
* Time Complexity: O(1)
|
|
454
|
-
* Space Complexity: O(1)
|
|
455
|
-
*
|
|
456
|
-
* The function "pollLast" removes and returns the last element of an array.
|
|
457
|
-
* @returns The last element of the array is being returned.
|
|
458
|
-
*/
|
|
459
|
-
pollLast(): E | undefined;
|
|
460
|
-
/**
|
|
461
|
-
* Time Complexity: O(1)
|
|
462
|
-
* Space Complexity: O(1)
|
|
463
|
-
* /
|
|
464
|
-
|
|
465
|
-
/**
|
|
466
|
-
* Time Complexity: O(1)
|
|
467
|
-
* Space Complexity: O(1)
|
|
468
|
-
*
|
|
469
|
-
* The "addFirst" function adds an element to the beginning of an array.
|
|
470
|
-
* @param {E} element - The parameter "element" represents the element that you want to add to the
|
|
471
|
-
* beginning of the data structure.
|
|
472
|
-
*/
|
|
473
|
-
addFirst(element: E): boolean;
|
|
474
|
-
/**
|
|
475
|
-
* Time Complexity: O(1)
|
|
476
|
-
* Space Complexity: O(1)
|
|
477
|
-
* /
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
* Time Complexity: O(1)
|
|
481
|
-
* Space Complexity: O(1)
|
|
482
|
-
*
|
|
483
|
-
* The function "pollFirst" removes and returns the first element of an array.
|
|
484
|
-
* @returns The method `pollFirst()` is returning the first element of the array after removing it
|
|
485
|
-
* from the beginning. If the array is empty, it will return `undefined`.
|
|
486
|
-
*/
|
|
487
|
-
pollFirst(): E | undefined;
|
|
488
435
|
/**
|
|
489
436
|
* Time Complexity: O(n)
|
|
490
437
|
* Space Complexity: O(1)
|
|
@@ -764,67 +764,6 @@ export class Deque extends IterableElementBase {
|
|
|
764
764
|
}
|
|
765
765
|
return newDeque;
|
|
766
766
|
}
|
|
767
|
-
/**
|
|
768
|
-
* Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
|
|
769
|
-
* Space Complexity: O(n) - Due to potential resizing.
|
|
770
|
-
*/
|
|
771
|
-
/**
|
|
772
|
-
* Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
|
|
773
|
-
* Space Complexity: O(n) - Due to potential resizing.
|
|
774
|
-
*
|
|
775
|
-
* The addLast function adds an element to the end of an array.
|
|
776
|
-
* @param {E} element - The element parameter represents the element that you want to add to the end of the
|
|
777
|
-
* data structure.
|
|
778
|
-
*/
|
|
779
|
-
addLast(element) {
|
|
780
|
-
return this.push(element);
|
|
781
|
-
}
|
|
782
|
-
/**
|
|
783
|
-
* Time Complexity: O(1)
|
|
784
|
-
* Space Complexity: O(1)
|
|
785
|
-
*/
|
|
786
|
-
/**
|
|
787
|
-
* Time Complexity: O(1)
|
|
788
|
-
* Space Complexity: O(1)
|
|
789
|
-
*
|
|
790
|
-
* The function "pollLast" removes and returns the last element of an array.
|
|
791
|
-
* @returns The last element of the array is being returned.
|
|
792
|
-
*/
|
|
793
|
-
pollLast() {
|
|
794
|
-
return this.pop();
|
|
795
|
-
}
|
|
796
|
-
/**
|
|
797
|
-
* Time Complexity: O(1)
|
|
798
|
-
* Space Complexity: O(1)
|
|
799
|
-
* /
|
|
800
|
-
|
|
801
|
-
/**
|
|
802
|
-
* Time Complexity: O(1)
|
|
803
|
-
* Space Complexity: O(1)
|
|
804
|
-
*
|
|
805
|
-
* The "addFirst" function adds an element to the beginning of an array.
|
|
806
|
-
* @param {E} element - The parameter "element" represents the element that you want to add to the
|
|
807
|
-
* beginning of the data structure.
|
|
808
|
-
*/
|
|
809
|
-
addFirst(element) {
|
|
810
|
-
return this.unshift(element);
|
|
811
|
-
}
|
|
812
|
-
/**
|
|
813
|
-
* Time Complexity: O(1)
|
|
814
|
-
* Space Complexity: O(1)
|
|
815
|
-
* /
|
|
816
|
-
|
|
817
|
-
/**
|
|
818
|
-
* Time Complexity: O(1)
|
|
819
|
-
* Space Complexity: O(1)
|
|
820
|
-
*
|
|
821
|
-
* The function "pollFirst" removes and returns the first element of an array.
|
|
822
|
-
* @returns The method `pollFirst()` is returning the first element of the array after removing it
|
|
823
|
-
* from the beginning. If the array is empty, it will return `undefined`.
|
|
824
|
-
*/
|
|
825
|
-
pollFirst() {
|
|
826
|
-
return this.shift();
|
|
827
|
-
}
|
|
828
767
|
/**
|
|
829
768
|
* Time Complexity: O(n)
|
|
830
769
|
* Space Complexity: O(1)
|
|
@@ -120,56 +120,6 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
120
120
|
* @return A boolean value
|
|
121
121
|
*/
|
|
122
122
|
deleteAt(index: number): boolean;
|
|
123
|
-
/**
|
|
124
|
-
* Time Complexity: O(1)
|
|
125
|
-
* Space Complexity: O(1)
|
|
126
|
-
*/
|
|
127
|
-
/**
|
|
128
|
-
* Time Complexity: O(1)
|
|
129
|
-
* Space Complexity: O(1)
|
|
130
|
-
*
|
|
131
|
-
* The `peek` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
|
|
132
|
-
* @returns The `peek()` method returns the first element of the data structure, represented by the `_elements` array at
|
|
133
|
-
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
134
|
-
*/
|
|
135
|
-
peek(): E | undefined;
|
|
136
|
-
/**
|
|
137
|
-
* Time Complexity: O(1)
|
|
138
|
-
* Space Complexity: O(1)
|
|
139
|
-
*/
|
|
140
|
-
/**
|
|
141
|
-
* Time Complexity: O(1)
|
|
142
|
-
* Space Complexity: O(1)
|
|
143
|
-
*
|
|
144
|
-
* The `peekLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
145
|
-
* @returns The method `peekLast()` returns the last element of the `_elements` array if the array is not empty. If the
|
|
146
|
-
* array is empty, it returns `undefined`.
|
|
147
|
-
*/
|
|
148
|
-
peekLast(): E | undefined;
|
|
149
|
-
/**
|
|
150
|
-
* Time Complexity: O(1)
|
|
151
|
-
* Space Complexity: O(1)
|
|
152
|
-
*/
|
|
153
|
-
/**
|
|
154
|
-
* Time Complexity: O(1)
|
|
155
|
-
* Space Complexity: O(1)
|
|
156
|
-
*
|
|
157
|
-
* The enqueue function adds a value to the end of a queue.
|
|
158
|
-
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
159
|
-
*/
|
|
160
|
-
enqueue(value: E): boolean;
|
|
161
|
-
/**
|
|
162
|
-
* Time Complexity: O(1)
|
|
163
|
-
* Space Complexity: O(1)
|
|
164
|
-
*/
|
|
165
|
-
/**
|
|
166
|
-
* Time Complexity: O(1)
|
|
167
|
-
* Space Complexity: O(1)
|
|
168
|
-
*
|
|
169
|
-
* The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
|
|
170
|
-
* @returns The method is returning a value of type E or undefined.
|
|
171
|
-
*/
|
|
172
|
-
dequeue(): E | undefined;
|
|
173
123
|
/**
|
|
174
124
|
* Time Complexity: O(1)
|
|
175
125
|
* Space Complexity: O(1)
|
|
@@ -288,26 +238,6 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
288
238
|
* 4. Frequent Enqueuing and Dequeuing Operations: If your application involves frequent enqueuing and dequeuing operations and is less concerned with random access, then LinkedListQueue is a good choice.
|
|
289
239
|
*/
|
|
290
240
|
export declare class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
|
|
291
|
-
/**
|
|
292
|
-
* The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
293
|
-
* @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
294
|
-
*/
|
|
295
|
-
get first(): E | undefined;
|
|
296
|
-
/**
|
|
297
|
-
* The enqueue function adds a value to the end of an array.
|
|
298
|
-
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
299
|
-
*/
|
|
300
|
-
enqueue(value: E): boolean;
|
|
301
|
-
/**
|
|
302
|
-
* The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
|
|
303
|
-
* @returns The method is returning the element at the front of the queue, or undefined if the queue is empty.
|
|
304
|
-
*/
|
|
305
|
-
dequeue(): E | undefined;
|
|
306
|
-
/**
|
|
307
|
-
* The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
308
|
-
* @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
309
|
-
*/
|
|
310
|
-
peek(): E | undefined;
|
|
311
241
|
/**
|
|
312
242
|
* Time Complexity: O(n)
|
|
313
243
|
* Space Complexity: O(n)
|
|
@@ -153,64 +153,6 @@ export class Queue extends IterableElementBase {
|
|
|
153
153
|
const spliced = this.elements.splice(index, 1);
|
|
154
154
|
return spliced.length === 1;
|
|
155
155
|
}
|
|
156
|
-
/**
|
|
157
|
-
* Time Complexity: O(1)
|
|
158
|
-
* Space Complexity: O(1)
|
|
159
|
-
*/
|
|
160
|
-
/**
|
|
161
|
-
* Time Complexity: O(1)
|
|
162
|
-
* Space Complexity: O(1)
|
|
163
|
-
*
|
|
164
|
-
* The `peek` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
|
|
165
|
-
* @returns The `peek()` method returns the first element of the data structure, represented by the `_elements` array at
|
|
166
|
-
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
167
|
-
*/
|
|
168
|
-
peek() {
|
|
169
|
-
return this.first;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Time Complexity: O(1)
|
|
173
|
-
* Space Complexity: O(1)
|
|
174
|
-
*/
|
|
175
|
-
/**
|
|
176
|
-
* Time Complexity: O(1)
|
|
177
|
-
* Space Complexity: O(1)
|
|
178
|
-
*
|
|
179
|
-
* The `peekLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
180
|
-
* @returns The method `peekLast()` returns the last element of the `_elements` array if the array is not empty. If the
|
|
181
|
-
* array is empty, it returns `undefined`.
|
|
182
|
-
*/
|
|
183
|
-
peekLast() {
|
|
184
|
-
return this.last;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Time Complexity: O(1)
|
|
188
|
-
* Space Complexity: O(1)
|
|
189
|
-
*/
|
|
190
|
-
/**
|
|
191
|
-
* Time Complexity: O(1)
|
|
192
|
-
* Space Complexity: O(1)
|
|
193
|
-
*
|
|
194
|
-
* The enqueue function adds a value to the end of a queue.
|
|
195
|
-
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
196
|
-
*/
|
|
197
|
-
enqueue(value) {
|
|
198
|
-
return this.push(value);
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Time Complexity: O(1)
|
|
202
|
-
* Space Complexity: O(1)
|
|
203
|
-
*/
|
|
204
|
-
/**
|
|
205
|
-
* Time Complexity: O(1)
|
|
206
|
-
* Space Complexity: O(1)
|
|
207
|
-
*
|
|
208
|
-
* The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
|
|
209
|
-
* @returns The method is returning a value of type E or undefined.
|
|
210
|
-
*/
|
|
211
|
-
dequeue() {
|
|
212
|
-
return this.shift();
|
|
213
|
-
}
|
|
214
156
|
/**
|
|
215
157
|
* Time Complexity: O(1)
|
|
216
158
|
* Space Complexity: O(1)
|
|
@@ -362,34 +304,6 @@ export class Queue extends IterableElementBase {
|
|
|
362
304
|
* 4. Frequent Enqueuing and Dequeuing Operations: If your application involves frequent enqueuing and dequeuing operations and is less concerned with random access, then LinkedListQueue is a good choice.
|
|
363
305
|
*/
|
|
364
306
|
export class LinkedListQueue extends SinglyLinkedList {
|
|
365
|
-
/**
|
|
366
|
-
* The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
367
|
-
* @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
368
|
-
*/
|
|
369
|
-
get first() {
|
|
370
|
-
return this.head?.value;
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* The enqueue function adds a value to the end of an array.
|
|
374
|
-
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
375
|
-
*/
|
|
376
|
-
enqueue(value) {
|
|
377
|
-
return this.push(value);
|
|
378
|
-
}
|
|
379
|
-
/**
|
|
380
|
-
* The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
|
|
381
|
-
* @returns The method is returning the element at the front of the queue, or undefined if the queue is empty.
|
|
382
|
-
*/
|
|
383
|
-
dequeue() {
|
|
384
|
-
return this.shift();
|
|
385
|
-
}
|
|
386
|
-
/**
|
|
387
|
-
* The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
388
|
-
* @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
389
|
-
*/
|
|
390
|
-
peek() {
|
|
391
|
-
return this.first;
|
|
392
|
-
}
|
|
393
307
|
/**
|
|
394
308
|
* Time Complexity: O(n)
|
|
395
309
|
* Space Complexity: O(n)
|