data-structure-typed 1.39.4 → 1.39.6
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 +3 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +6 -6
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +13 -13
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +7 -7
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +17 -17
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +6 -6
- package/dist/cjs/data-structures/binary-tree/bst.js +13 -13
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +2 -2
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +4 -4
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +7 -7
- package/dist/cjs/data-structures/binary-tree/segment-tree.js +16 -16
- package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multiset.d.ts +6 -6
- package/dist/cjs/data-structures/binary-tree/tree-multiset.js +18 -18
- package/dist/cjs/data-structures/binary-tree/tree-multiset.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +96 -96
- package/dist/cjs/data-structures/graph/abstract-graph.js +64 -64
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +68 -68
- package/dist/cjs/data-structures/graph/directed-graph.js +48 -48
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.d.ts +13 -13
- package/dist/cjs/data-structures/graph/map-graph.js +15 -15
- package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +42 -42
- package/dist/cjs/data-structures/graph/undirected-graph.js +32 -32
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-table.d.ts +4 -4
- package/dist/cjs/data-structures/hash/hash-table.js +8 -8
- package/dist/cjs/data-structures/hash/hash-table.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +31 -31
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +54 -54
- 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 +24 -24
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +52 -52
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +1 -1
- package/dist/cjs/data-structures/queue/queue.js +4 -4
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +2 -2
- package/dist/cjs/interfaces/graph.d.ts +3 -3
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +6 -6
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +13 -13
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +7 -7
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +18 -18
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +6 -6
- package/dist/mjs/data-structures/binary-tree/bst.js +13 -13
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +2 -2
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +4 -4
- package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +7 -7
- package/dist/mjs/data-structures/binary-tree/segment-tree.js +16 -16
- package/dist/mjs/data-structures/binary-tree/tree-multiset.d.ts +6 -6
- package/dist/mjs/data-structures/binary-tree/tree-multiset.js +18 -18
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +96 -96
- package/dist/mjs/data-structures/graph/abstract-graph.js +66 -66
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +68 -68
- package/dist/mjs/data-structures/graph/directed-graph.js +48 -48
- package/dist/mjs/data-structures/graph/map-graph.d.ts +13 -13
- package/dist/mjs/data-structures/graph/map-graph.js +15 -15
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +42 -42
- package/dist/mjs/data-structures/graph/undirected-graph.js +32 -32
- package/dist/mjs/data-structures/hash/hash-table.d.ts +4 -4
- package/dist/mjs/data-structures/hash/hash-table.js +9 -9
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +31 -31
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +55 -55
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +24 -24
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +53 -53
- package/dist/mjs/data-structures/queue/queue.d.ts +1 -1
- package/dist/mjs/data-structures/queue/queue.js +4 -4
- package/dist/mjs/interfaces/binary-tree.d.ts +2 -2
- package/dist/mjs/interfaces/graph.d.ts +3 -3
- package/dist/umd/data-structure-typed.min.js +1 -1
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +5 -5
- package/src/data-structures/binary-tree/avl-tree.ts +13 -13
- package/src/data-structures/binary-tree/binary-tree.ts +18 -18
- package/src/data-structures/binary-tree/bst.ts +16 -16
- package/src/data-structures/binary-tree/rb-tree.ts +6 -6
- package/src/data-structures/binary-tree/segment-tree.ts +15 -15
- package/src/data-structures/binary-tree/tree-multiset.ts +18 -18
- package/src/data-structures/graph/abstract-graph.ts +156 -154
- package/src/data-structures/graph/directed-graph.ts +99 -94
- package/src/data-structures/graph/map-graph.ts +22 -25
- package/src/data-structures/graph/undirected-graph.ts +62 -60
- package/src/data-structures/hash/hash-table.ts +9 -9
- package/src/data-structures/linked-list/doubly-linked-list.ts +61 -61
- package/src/data-structures/linked-list/singly-linked-list.ts +58 -58
- package/src/data-structures/queue/queue.ts +2 -2
- package/src/interfaces/binary-tree.ts +2 -2
- package/src/interfaces/graph.ts +3 -3
- package/test/integration/bst.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +8 -8
- package/test/unit/data-structures/binary-tree/bst.test.ts +4 -4
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +2 -2
- package/test/unit/data-structures/graph/abstract-graph.test.ts +99 -2
- package/test/unit/data-structures/graph/directed-graph.test.ts +38 -23
- package/test/unit/data-structures/graph/map-graph.test.ts +23 -23
- package/test/unit/data-structures/graph/undirected-graph.test.ts +10 -2
- package/test/unit/data-structures/hash/hash-table.test.ts +1 -1
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +30 -30
- package/test/unit/data-structures/linked-list/linked-list.test.ts +1 -1
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +15 -15
- package/test/unit/data-structures/queue/queue.test.ts +8 -8
- package/test/utils/big-o.ts +7 -7
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
export declare class SinglyLinkedListNode<E = any> {
|
|
9
9
|
/**
|
|
10
10
|
* The constructor function initializes an instance of a class with a given value and sets the next property to null.
|
|
11
|
-
* @param {E}
|
|
11
|
+
* @param {E} value - The "value" parameter is of type E, which means it can be any data type. It represents the value that
|
|
12
12
|
* will be stored in the node of a linked list.
|
|
13
13
|
*/
|
|
14
|
-
constructor(
|
|
15
|
-
private
|
|
16
|
-
get
|
|
17
|
-
set
|
|
14
|
+
constructor(value: E);
|
|
15
|
+
private _value;
|
|
16
|
+
get value(): E;
|
|
17
|
+
set value(value: E);
|
|
18
18
|
private _next;
|
|
19
19
|
get next(): SinglyLinkedListNode<E> | null;
|
|
20
20
|
set next(value: SinglyLinkedListNode<E> | null);
|
|
@@ -40,17 +40,17 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
40
40
|
*/
|
|
41
41
|
static fromArray<E>(data: E[]): SinglyLinkedList<E>;
|
|
42
42
|
/**
|
|
43
|
-
* The `push` function adds a new node with the given
|
|
44
|
-
* @param {E}
|
|
43
|
+
* The `push` function adds a new node with the given value to the end of a singly linked list.
|
|
44
|
+
* @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
|
|
45
45
|
* any type (E) as specified in the generic type declaration of the class or function.
|
|
46
46
|
*/
|
|
47
|
-
push(
|
|
47
|
+
push(value: E): void;
|
|
48
48
|
/**
|
|
49
|
-
* The `push` function adds a new node with the given
|
|
50
|
-
* @param {E}
|
|
49
|
+
* The `push` function adds a new node with the given value to the end of a singly linked list.
|
|
50
|
+
* @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
|
|
51
51
|
* any type (E) as specified in the generic type declaration of the class or function.
|
|
52
52
|
*/
|
|
53
|
-
addLast(
|
|
53
|
+
addLast(value: E): void;
|
|
54
54
|
/**
|
|
55
55
|
* The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
|
|
56
56
|
* pointers accordingly.
|
|
@@ -77,16 +77,16 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
77
77
|
popFirst(): E | undefined;
|
|
78
78
|
/**
|
|
79
79
|
* The unshift function adds a new node with the given value to the beginning of a singly linked list.
|
|
80
|
-
* @param {E}
|
|
80
|
+
* @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
|
|
81
81
|
* linked list.
|
|
82
82
|
*/
|
|
83
|
-
unshift(
|
|
83
|
+
unshift(value: E): void;
|
|
84
84
|
/**
|
|
85
85
|
* The addFirst function adds a new node with the given value to the beginning of a singly linked list.
|
|
86
|
-
* @param {E}
|
|
86
|
+
* @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
|
|
87
87
|
* linked list.
|
|
88
88
|
*/
|
|
89
|
-
addFirst(
|
|
89
|
+
addFirst(value: E): void;
|
|
90
90
|
/**
|
|
91
91
|
* The function `getAt` returns the value at a specified index in a linked list, or null if the index is out of range.
|
|
92
92
|
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
@@ -123,12 +123,12 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
123
123
|
* The `insertAt` function inserts a value at a specified index in a singly linked list.
|
|
124
124
|
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
125
125
|
* linked list. It is of type number.
|
|
126
|
-
* @param {E}
|
|
126
|
+
* @param {E} value - The `value` parameter represents the value that you want to insert into the linked list at the
|
|
127
127
|
* specified index.
|
|
128
128
|
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
|
|
129
129
|
* if the index is out of bounds.
|
|
130
130
|
*/
|
|
131
|
-
insertAt(index: number,
|
|
131
|
+
insertAt(index: number, value: E): boolean;
|
|
132
132
|
/**
|
|
133
133
|
* The function checks if the length of a data structure is equal to zero and returns a boolean value indicating
|
|
134
134
|
* whether it is empty or not.
|
|
@@ -156,7 +156,7 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
156
156
|
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
|
|
157
157
|
* the callback function. If no element satisfies the condition, it returns `null`.
|
|
158
158
|
*/
|
|
159
|
-
find(callback: (
|
|
159
|
+
find(callback: (value: E) => boolean): E | null;
|
|
160
160
|
/**
|
|
161
161
|
* The `indexOf` function returns the index of the first occurrence of a given value in a linked list.
|
|
162
162
|
* @param {E} value - The value parameter is the value that you want to find the index of in the linked list.
|
|
@@ -198,11 +198,11 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
198
198
|
countOccurrences(value: E): number;
|
|
199
199
|
/**
|
|
200
200
|
* The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
|
|
201
|
-
* @param callback - The callback parameter is a function that takes two arguments:
|
|
201
|
+
* @param callback - The callback parameter is a function that takes two arguments: value and index. The value argument
|
|
202
202
|
* represents the value of the current node in the linked list, and the index argument represents the index of the
|
|
203
203
|
* current node in the linked list.
|
|
204
204
|
*/
|
|
205
|
-
forEach(callback: (
|
|
205
|
+
forEach(callback: (value: E, index: number) => void): void;
|
|
206
206
|
/**
|
|
207
207
|
* The `map` function takes a callback function and applies it to each element in the SinglyLinkedList, returning a new
|
|
208
208
|
* SinglyLinkedList with the transformed values.
|
|
@@ -211,7 +211,7 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
211
211
|
* SinglyLinkedList).
|
|
212
212
|
* @returns The `map` function is returning a new instance of `SinglyLinkedList<U>` that contains the mapped values.
|
|
213
213
|
*/
|
|
214
|
-
map<U>(callback: (
|
|
214
|
+
map<U>(callback: (value: E) => U): SinglyLinkedList<U>;
|
|
215
215
|
/**
|
|
216
216
|
* The `filter` function iterates through a SinglyLinkedList and returns a new SinglyLinkedList containing only the
|
|
217
217
|
* elements that satisfy the given callback function.
|
|
@@ -219,18 +219,18 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
219
219
|
* It is used to determine whether a value should be included in the filtered list or not.
|
|
220
220
|
* @returns The filtered list, which is an instance of the SinglyLinkedList class.
|
|
221
221
|
*/
|
|
222
|
-
filter(callback: (
|
|
222
|
+
filter(callback: (value: E) => boolean): SinglyLinkedList<E>;
|
|
223
223
|
/**
|
|
224
224
|
* The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
|
|
225
225
|
* single value.
|
|
226
|
-
* @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `
|
|
226
|
+
* @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `value`. It is
|
|
227
227
|
* used to perform a specific operation on each element of the linked list.
|
|
228
228
|
* @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
|
|
229
229
|
* point for the reduction operation.
|
|
230
230
|
* @returns The `reduce` method is returning the final value of the accumulator after iterating through all the
|
|
231
231
|
* elements in the linked list.
|
|
232
232
|
*/
|
|
233
|
-
reduce<U>(callback: (accumulator: U,
|
|
233
|
+
reduce<U>(callback: (accumulator: U, value: E) => U, initialValue: U): U;
|
|
234
234
|
/**
|
|
235
235
|
* The function returns an iterator that iterates over the values of a linked list.
|
|
236
236
|
*/
|
|
@@ -11,18 +11,18 @@ exports.SinglyLinkedList = exports.SinglyLinkedListNode = void 0;
|
|
|
11
11
|
class SinglyLinkedListNode {
|
|
12
12
|
/**
|
|
13
13
|
* The constructor function initializes an instance of a class with a given value and sets the next property to null.
|
|
14
|
-
* @param {E}
|
|
14
|
+
* @param {E} value - The "value" parameter is of type E, which means it can be any data type. It represents the value that
|
|
15
15
|
* will be stored in the node of a linked list.
|
|
16
16
|
*/
|
|
17
|
-
constructor(
|
|
18
|
-
this.
|
|
17
|
+
constructor(value) {
|
|
18
|
+
this._value = value;
|
|
19
19
|
this._next = null;
|
|
20
20
|
}
|
|
21
|
-
get
|
|
22
|
-
return this.
|
|
21
|
+
get value() {
|
|
22
|
+
return this._value;
|
|
23
23
|
}
|
|
24
|
-
set
|
|
25
|
-
this.
|
|
24
|
+
set value(value) {
|
|
25
|
+
this._value = value;
|
|
26
26
|
}
|
|
27
27
|
get next() {
|
|
28
28
|
return this._next;
|
|
@@ -70,12 +70,12 @@ class SinglyLinkedList {
|
|
|
70
70
|
return singlyLinkedList;
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
|
-
* The `push` function adds a new node with the given
|
|
74
|
-
* @param {E}
|
|
73
|
+
* The `push` function adds a new node with the given value to the end of a singly linked list.
|
|
74
|
+
* @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
|
|
75
75
|
* any type (E) as specified in the generic type declaration of the class or function.
|
|
76
76
|
*/
|
|
77
|
-
push(
|
|
78
|
-
const newNode = new SinglyLinkedListNode(
|
|
77
|
+
push(value) {
|
|
78
|
+
const newNode = new SinglyLinkedListNode(value);
|
|
79
79
|
if (!this.head) {
|
|
80
80
|
this.head = newNode;
|
|
81
81
|
this.tail = newNode;
|
|
@@ -87,12 +87,12 @@ class SinglyLinkedList {
|
|
|
87
87
|
this._length++;
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
|
-
* The `push` function adds a new node with the given
|
|
91
|
-
* @param {E}
|
|
90
|
+
* The `push` function adds a new node with the given value to the end of a singly linked list.
|
|
91
|
+
* @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
|
|
92
92
|
* any type (E) as specified in the generic type declaration of the class or function.
|
|
93
93
|
*/
|
|
94
|
-
addLast(
|
|
95
|
-
this.push(
|
|
94
|
+
addLast(value) {
|
|
95
|
+
this.push(value);
|
|
96
96
|
}
|
|
97
97
|
/**
|
|
98
98
|
* The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
|
|
@@ -104,21 +104,21 @@ class SinglyLinkedList {
|
|
|
104
104
|
if (!this.head)
|
|
105
105
|
return undefined;
|
|
106
106
|
if (this.head === this.tail) {
|
|
107
|
-
const
|
|
107
|
+
const value = this.head.value;
|
|
108
108
|
this.head = null;
|
|
109
109
|
this.tail = null;
|
|
110
110
|
this._length--;
|
|
111
|
-
return
|
|
111
|
+
return value;
|
|
112
112
|
}
|
|
113
113
|
let current = this.head;
|
|
114
114
|
while (current.next !== this.tail) {
|
|
115
115
|
current = current.next;
|
|
116
116
|
}
|
|
117
|
-
const
|
|
117
|
+
const value = this.tail.value;
|
|
118
118
|
current.next = null;
|
|
119
119
|
this.tail = current;
|
|
120
120
|
this._length--;
|
|
121
|
-
return
|
|
121
|
+
return value;
|
|
122
122
|
}
|
|
123
123
|
/**
|
|
124
124
|
* The `popLast()` function removes and returns the value of the last element in a linked list, updating the head and tail
|
|
@@ -139,7 +139,7 @@ class SinglyLinkedList {
|
|
|
139
139
|
const removedNode = this.head;
|
|
140
140
|
this.head = this.head.next;
|
|
141
141
|
this._length--;
|
|
142
|
-
return removedNode.
|
|
142
|
+
return removedNode.value;
|
|
143
143
|
}
|
|
144
144
|
/**
|
|
145
145
|
* The `popFirst()` function removes and returns the value of the first node in a linked list.
|
|
@@ -150,11 +150,11 @@ class SinglyLinkedList {
|
|
|
150
150
|
}
|
|
151
151
|
/**
|
|
152
152
|
* The unshift function adds a new node with the given value to the beginning of a singly linked list.
|
|
153
|
-
* @param {E}
|
|
153
|
+
* @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
|
|
154
154
|
* linked list.
|
|
155
155
|
*/
|
|
156
|
-
unshift(
|
|
157
|
-
const newNode = new SinglyLinkedListNode(
|
|
156
|
+
unshift(value) {
|
|
157
|
+
const newNode = new SinglyLinkedListNode(value);
|
|
158
158
|
if (!this.head) {
|
|
159
159
|
this.head = newNode;
|
|
160
160
|
this.tail = newNode;
|
|
@@ -167,11 +167,11 @@ class SinglyLinkedList {
|
|
|
167
167
|
}
|
|
168
168
|
/**
|
|
169
169
|
* The addFirst function adds a new node with the given value to the beginning of a singly linked list.
|
|
170
|
-
* @param {E}
|
|
170
|
+
* @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
|
|
171
171
|
* linked list.
|
|
172
172
|
*/
|
|
173
|
-
addFirst(
|
|
174
|
-
this.unshift(
|
|
173
|
+
addFirst(value) {
|
|
174
|
+
this.unshift(value);
|
|
175
175
|
}
|
|
176
176
|
/**
|
|
177
177
|
* The function `getAt` returns the value at a specified index in a linked list, or null if the index is out of range.
|
|
@@ -187,7 +187,7 @@ class SinglyLinkedList {
|
|
|
187
187
|
for (let i = 0; i < index; i++) {
|
|
188
188
|
current = current.next;
|
|
189
189
|
}
|
|
190
|
-
return current.
|
|
190
|
+
return current.value;
|
|
191
191
|
}
|
|
192
192
|
/**
|
|
193
193
|
* The function `getNodeAt` returns the node at a given index in a singly linked list.
|
|
@@ -221,7 +221,7 @@ class SinglyLinkedList {
|
|
|
221
221
|
const removedNode = prevNode.next;
|
|
222
222
|
prevNode.next = removedNode.next;
|
|
223
223
|
this._length--;
|
|
224
|
-
return removedNode.
|
|
224
|
+
return removedNode.value;
|
|
225
225
|
}
|
|
226
226
|
/**
|
|
227
227
|
* The delete function removes a node with a specific value from a singly linked list.
|
|
@@ -235,14 +235,14 @@ class SinglyLinkedList {
|
|
|
235
235
|
return false;
|
|
236
236
|
let value;
|
|
237
237
|
if (valueOrNode instanceof SinglyLinkedListNode) {
|
|
238
|
-
value = valueOrNode.
|
|
238
|
+
value = valueOrNode.value;
|
|
239
239
|
}
|
|
240
240
|
else {
|
|
241
241
|
value = valueOrNode;
|
|
242
242
|
}
|
|
243
243
|
let current = this.head, prev = null;
|
|
244
244
|
while (current) {
|
|
245
|
-
if (current.
|
|
245
|
+
if (current.value === value) {
|
|
246
246
|
if (prev === null) {
|
|
247
247
|
this.head = current.next;
|
|
248
248
|
if (current === this.tail) {
|
|
@@ -267,23 +267,23 @@ class SinglyLinkedList {
|
|
|
267
267
|
* The `insertAt` function inserts a value at a specified index in a singly linked list.
|
|
268
268
|
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
269
269
|
* linked list. It is of type number.
|
|
270
|
-
* @param {E}
|
|
270
|
+
* @param {E} value - The `value` parameter represents the value that you want to insert into the linked list at the
|
|
271
271
|
* specified index.
|
|
272
272
|
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
|
|
273
273
|
* if the index is out of bounds.
|
|
274
274
|
*/
|
|
275
|
-
insertAt(index,
|
|
275
|
+
insertAt(index, value) {
|
|
276
276
|
if (index < 0 || index > this.length)
|
|
277
277
|
return false;
|
|
278
278
|
if (index === 0) {
|
|
279
|
-
this.unshift(
|
|
279
|
+
this.unshift(value);
|
|
280
280
|
return true;
|
|
281
281
|
}
|
|
282
282
|
if (index === this.length) {
|
|
283
|
-
this.push(
|
|
283
|
+
this.push(value);
|
|
284
284
|
return true;
|
|
285
285
|
}
|
|
286
|
-
const newNode = new SinglyLinkedListNode(
|
|
286
|
+
const newNode = new SinglyLinkedListNode(value);
|
|
287
287
|
const prevNode = this.getNodeAt(index - 1);
|
|
288
288
|
newNode.next = prevNode.next;
|
|
289
289
|
prevNode.next = newNode;
|
|
@@ -314,7 +314,7 @@ class SinglyLinkedList {
|
|
|
314
314
|
const array = [];
|
|
315
315
|
let current = this.head;
|
|
316
316
|
while (current) {
|
|
317
|
-
array.push(current.
|
|
317
|
+
array.push(current.value);
|
|
318
318
|
current = current.next;
|
|
319
319
|
}
|
|
320
320
|
return array;
|
|
@@ -347,8 +347,8 @@ class SinglyLinkedList {
|
|
|
347
347
|
find(callback) {
|
|
348
348
|
let current = this.head;
|
|
349
349
|
while (current) {
|
|
350
|
-
if (callback(current.
|
|
351
|
-
return current.
|
|
350
|
+
if (callback(current.value)) {
|
|
351
|
+
return current.value;
|
|
352
352
|
}
|
|
353
353
|
current = current.next;
|
|
354
354
|
}
|
|
@@ -364,7 +364,7 @@ class SinglyLinkedList {
|
|
|
364
364
|
let index = 0;
|
|
365
365
|
let current = this.head;
|
|
366
366
|
while (current) {
|
|
367
|
-
if (current.
|
|
367
|
+
if (current.value === value) {
|
|
368
368
|
return index;
|
|
369
369
|
}
|
|
370
370
|
index++;
|
|
@@ -382,7 +382,7 @@ class SinglyLinkedList {
|
|
|
382
382
|
getNode(value) {
|
|
383
383
|
let current = this.head;
|
|
384
384
|
while (current) {
|
|
385
|
-
if (current.
|
|
385
|
+
if (current.value === value) {
|
|
386
386
|
return current;
|
|
387
387
|
}
|
|
388
388
|
current = current.next;
|
|
@@ -402,18 +402,18 @@ class SinglyLinkedList {
|
|
|
402
402
|
return false;
|
|
403
403
|
let existingValue;
|
|
404
404
|
if (existingValueOrNode instanceof SinglyLinkedListNode) {
|
|
405
|
-
existingValue = existingValueOrNode.
|
|
405
|
+
existingValue = existingValueOrNode.value;
|
|
406
406
|
}
|
|
407
407
|
else {
|
|
408
408
|
existingValue = existingValueOrNode;
|
|
409
409
|
}
|
|
410
|
-
if (this.head.
|
|
410
|
+
if (this.head.value === existingValue) {
|
|
411
411
|
this.unshift(newValue);
|
|
412
412
|
return true;
|
|
413
413
|
}
|
|
414
414
|
let current = this.head;
|
|
415
415
|
while (current.next) {
|
|
416
|
-
if (current.next.
|
|
416
|
+
if (current.next.value === existingValue) {
|
|
417
417
|
const newNode = new SinglyLinkedListNode(newValue);
|
|
418
418
|
newNode.next = current.next;
|
|
419
419
|
current.next = newNode;
|
|
@@ -461,7 +461,7 @@ class SinglyLinkedList {
|
|
|
461
461
|
let count = 0;
|
|
462
462
|
let current = this.head;
|
|
463
463
|
while (current) {
|
|
464
|
-
if (current.
|
|
464
|
+
if (current.value === value) {
|
|
465
465
|
count++;
|
|
466
466
|
}
|
|
467
467
|
current = current.next;
|
|
@@ -470,7 +470,7 @@ class SinglyLinkedList {
|
|
|
470
470
|
}
|
|
471
471
|
/**
|
|
472
472
|
* The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
|
|
473
|
-
* @param callback - The callback parameter is a function that takes two arguments:
|
|
473
|
+
* @param callback - The callback parameter is a function that takes two arguments: value and index. The value argument
|
|
474
474
|
* represents the value of the current node in the linked list, and the index argument represents the index of the
|
|
475
475
|
* current node in the linked list.
|
|
476
476
|
*/
|
|
@@ -478,7 +478,7 @@ class SinglyLinkedList {
|
|
|
478
478
|
let current = this.head;
|
|
479
479
|
let index = 0;
|
|
480
480
|
while (current) {
|
|
481
|
-
callback(current.
|
|
481
|
+
callback(current.value, index);
|
|
482
482
|
current = current.next;
|
|
483
483
|
index++;
|
|
484
484
|
}
|
|
@@ -495,7 +495,7 @@ class SinglyLinkedList {
|
|
|
495
495
|
const mappedList = new SinglyLinkedList();
|
|
496
496
|
let current = this.head;
|
|
497
497
|
while (current) {
|
|
498
|
-
mappedList.push(callback(current.
|
|
498
|
+
mappedList.push(callback(current.value));
|
|
499
499
|
current = current.next;
|
|
500
500
|
}
|
|
501
501
|
return mappedList;
|
|
@@ -511,8 +511,8 @@ class SinglyLinkedList {
|
|
|
511
511
|
const filteredList = new SinglyLinkedList();
|
|
512
512
|
let current = this.head;
|
|
513
513
|
while (current) {
|
|
514
|
-
if (callback(current.
|
|
515
|
-
filteredList.push(current.
|
|
514
|
+
if (callback(current.value)) {
|
|
515
|
+
filteredList.push(current.value);
|
|
516
516
|
}
|
|
517
517
|
current = current.next;
|
|
518
518
|
}
|
|
@@ -521,7 +521,7 @@ class SinglyLinkedList {
|
|
|
521
521
|
/**
|
|
522
522
|
* The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
|
|
523
523
|
* single value.
|
|
524
|
-
* @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `
|
|
524
|
+
* @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `value`. It is
|
|
525
525
|
* used to perform a specific operation on each element of the linked list.
|
|
526
526
|
* @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
|
|
527
527
|
* point for the reduction operation.
|
|
@@ -532,7 +532,7 @@ class SinglyLinkedList {
|
|
|
532
532
|
let accumulator = initialValue;
|
|
533
533
|
let current = this.head;
|
|
534
534
|
while (current) {
|
|
535
|
-
accumulator = callback(accumulator, current.
|
|
535
|
+
accumulator = callback(accumulator, current.value);
|
|
536
536
|
current = current.next;
|
|
537
537
|
}
|
|
538
538
|
return accumulator;
|
|
@@ -543,7 +543,7 @@ class SinglyLinkedList {
|
|
|
543
543
|
*[Symbol.iterator]() {
|
|
544
544
|
let current = this.head;
|
|
545
545
|
while (current) {
|
|
546
|
-
yield current.
|
|
546
|
+
yield current.value;
|
|
547
547
|
current = current.next;
|
|
548
548
|
}
|
|
549
549
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"singly-linked-list.js","sourceRoot":"","sources":["../../../../src/data-structures/linked-list/singly-linked-list.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,MAAa,oBAAoB;IAC/B;;;;OAIG;IACH,YAAY,GAAM;QAChB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,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,CAA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E;YACd,MAAM,OAAO,CAAC,GAAG,CAAC;YAClB,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;SACxB;IACH,CAAC;CACF;AAjjBD,4CAijBC"}
|
|
1
|
+
{"version":3,"file":"singly-linked-list.js","sourceRoot":"","sources":["../../../../src/data-structures/linked-list/singly-linked-list.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,MAAa,oBAAoB;IAC/B;;;;OAIG;IACH,YAAY,KAAQ;QAClB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAID,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,IAAI,KAAK,CAAC,KAAQ;QAChB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,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;CACF;AA9BD,oDA8BC;AAED,MAAa,gBAAgB;IAC3B;;OAEG;IACH;QACE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;IACnB,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,CAAC,KAAqC;QAC5C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAID,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC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C;aAClC;YACD,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;SACxB;QACD,OAAO,YAAY,CAAC;IACtB,CAAC;IAED;;;;;;;;;OASG;IACH,MAAM,CAAI,QAAyC,EAAE,YAAe;QAClE,IAAI,WAAW,GAAG,YAAY,CAAC;QAC/B,IAAI,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC;QACxB,OAAO,OAAO,EAAE;YACd,WAAW,GAAG,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;YACnD,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;SACxB;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,IAAI,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC;QAExB,OAAO,OAAO,EAAE;YACd,MAAM,OAAO,CAAC,KAAK,CAAC;YACpB,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;SACxB;IACH,CAAC;CACF;AAjjBD,4CAijBC"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @class
|
|
5
5
|
*/
|
|
6
6
|
import { SinglyLinkedList } from '../linked-list';
|
|
7
|
-
export declare class
|
|
7
|
+
export declare class SkipQueue<E = any> extends SinglyLinkedList<E> {
|
|
8
8
|
/**
|
|
9
9
|
* The enqueue function adds a value to the end of an array.
|
|
10
10
|
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Queue = exports.
|
|
3
|
+
exports.Queue = exports.SkipQueue = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* @license MIT
|
|
6
6
|
* @copyright Tyler Zeng <zrwusa@gmail.com>
|
|
7
7
|
* @class
|
|
8
8
|
*/
|
|
9
9
|
const linked_list_1 = require("../linked-list");
|
|
10
|
-
class
|
|
10
|
+
class SkipQueue extends linked_list_1.SinglyLinkedList {
|
|
11
11
|
/**
|
|
12
12
|
* The enqueue function adds a value to the end of an array.
|
|
13
13
|
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
@@ -28,10 +28,10 @@ class LinkedListQueue extends linked_list_1.SinglyLinkedList {
|
|
|
28
28
|
*/
|
|
29
29
|
peek() {
|
|
30
30
|
var _a;
|
|
31
|
-
return (_a = this.head) === null || _a === void 0 ? void 0 : _a.
|
|
31
|
+
return (_a = this.head) === null || _a === void 0 ? void 0 : _a.value;
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
exports.
|
|
34
|
+
exports.SkipQueue = SkipQueue;
|
|
35
35
|
class Queue {
|
|
36
36
|
/**
|
|
37
37
|
* The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../../src/data-structures/queue/queue.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,gDAAgD;AAEhD,MAAa,
|
|
1
|
+
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../../src/data-structures/queue/queue.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,gDAAgD;AAEhD,MAAa,SAAmB,SAAQ,8BAAmB;IACzD;;;OAGG;IACH,OAAO,CAAC,KAAQ;QACd,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,IAAI;;QACF,OAAO,MAAA,IAAI,CAAC,IAAI,0CAAE,KAAK,CAAC;IAC1B,CAAC;CACF;AAxBD,8BAwBC;AAED,MAAa,KAAK;IAChB;;;;;OAKG;IACH,YAAY,QAAc;QACxB,IAAI,CAAC,MAAM,GAAG,QAAQ,IAAI,EAAE,CAAC;QAC7B,IAAI,CAAC,OAA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|
1
1
|
import { BinaryTreeNode } from '../data-structures';
|
|
2
2
|
import { BinaryTreeDeletedResult, BTNKey, BinaryTreeNodeNested, BTNCallback } from '../types';
|
|
3
3
|
export interface IBinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNodeNested<V>> {
|
|
4
|
-
createNode(key: BTNKey,
|
|
5
|
-
add(keyOrNode: BTNKey | N | null,
|
|
4
|
+
createNode(key: BTNKey, value?: N['value']): N;
|
|
5
|
+
add(keyOrNode: BTNKey | N | null, value?: N['value']): N | null | undefined;
|
|
6
6
|
delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C): BinaryTreeDeletedResult<N>[];
|
|
7
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { VertexKey } from '../types';
|
|
2
|
-
export interface IGraph<V, E> {
|
|
3
|
-
createVertex(key: VertexKey,
|
|
4
|
-
createEdge(srcOrV1: VertexKey
|
|
2
|
+
export interface IGraph<V, E, VO, EO> {
|
|
3
|
+
createVertex(key: VertexKey, value?: V): VO;
|
|
4
|
+
createEdge(srcOrV1: VertexKey, destOrV2: VertexKey, weight?: number, value?: E): EO;
|
|
5
5
|
}
|
|
@@ -11,7 +11,7 @@ import { BTNCallback } from '../../types';
|
|
|
11
11
|
import { IBinaryTree } from '../../interfaces';
|
|
12
12
|
export declare class AVLTreeNode<V = any, N extends AVLTreeNode<V, N> = AVLTreeNodeNested<V>> extends BSTNode<V, N> {
|
|
13
13
|
height: number;
|
|
14
|
-
constructor(key: BTNKey,
|
|
14
|
+
constructor(key: BTNKey, value?: V);
|
|
15
15
|
}
|
|
16
16
|
export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTreeNodeNested<V>>> extends BST<V, N> implements IBinaryTree<V, N> {
|
|
17
17
|
/**
|
|
@@ -25,22 +25,22 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
|
|
|
25
25
|
* The function creates a new AVL tree node with the specified key and value.
|
|
26
26
|
* @param {BTNKey} key - The key parameter is the key value that will be associated with
|
|
27
27
|
* the new node. It is used to determine the position of the node in the binary search tree.
|
|
28
|
-
* @param [
|
|
29
|
-
* type `V`, which means it can be any value that is assignable to the `
|
|
28
|
+
* @param [value] - The parameter `value` is an optional value that can be assigned to the node. It is of
|
|
29
|
+
* type `V`, which means it can be any value that is assignable to the `value` property of the
|
|
30
30
|
* node type `N`.
|
|
31
31
|
* @returns a new AVLTreeNode object with the specified key and value.
|
|
32
32
|
*/
|
|
33
|
-
createNode(key: BTNKey,
|
|
33
|
+
createNode(key: BTNKey, value?: V): N;
|
|
34
34
|
/**
|
|
35
35
|
* The function overrides the add method of a binary tree node and balances the tree after inserting
|
|
36
36
|
* a new node.
|
|
37
37
|
* @param {BTNKey | N | null} keyOrNode - The `keyOrNode` parameter can accept either a
|
|
38
38
|
* `BTNKey` or a `N` (which represents a node in the binary tree) or `null`.
|
|
39
|
-
* @param [
|
|
39
|
+
* @param [value] - The `value` parameter is the value that you want to assign to the new node that you
|
|
40
40
|
* are adding to the binary search tree.
|
|
41
41
|
* @returns The method is returning the inserted node (`N`), `null`, or `undefined`.
|
|
42
42
|
*/
|
|
43
|
-
add(keyOrNode: BTNKey | N | null,
|
|
43
|
+
add(keyOrNode: BTNKey | N | null, value?: V): N | null | undefined;
|
|
44
44
|
/**
|
|
45
45
|
* The function overrides the delete method of a binary tree and balances the tree after deleting a
|
|
46
46
|
* node if necessary.
|