linked-list-typed 1.19.3 → 1.19.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/README.md +10 -204
- package/dist/index.d.ts +8 -2
- package/dist/index.js +13 -16
- package/package.json +2 -2
- package/tsconfig.json +6 -4
- package/dist/doubly-linked-list.d.ts +0 -195
- package/dist/doubly-linked-list.js +0 -591
- package/dist/singly-linked-list.d.ts +0 -156
- package/dist/singly-linked-list.js +0 -502
package/README.md
CHANGED
|
@@ -1,180 +1,30 @@
|
|
|
1
1
|
# What
|
|
2
|
-
|
|
3
2
|
## Brief
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Binary Tree, Binary Search Tree (BST), AVL Tree, Tree Multiset, Segment Tree, Binary Indexed Tree, Graph, Directed Graph, Undirected Graph, Linked List, Singly Linked List, Doubly Linked List, Queue, Object Deque, Array Deque, Stack, Hash, Coordinate Set, Coordinate Map, Heap, Priority Queue, Max Priority Queue, Min Priority Queue, Trie
|
|
7
|
-
|
|
8
|
-
## Algorithms list only a few out, you can discover more in API docs
|
|
3
|
+
This is a standalone Linked List data structure from the data-structure-typed collection. If you wish to access more data structures or advanced features, you can transition to directly installing the complete [data-structure-typed](https://www.npmjs.com/package/data-structure-typed) package
|
|
9
4
|
|
|
10
|
-
DFS, DFSIterative, BFS, morris, Bellman-Ford Algorithm, Dijkstra's Algorithm, Floyd-Warshall Algorithm, Tarjan's Algorithm
|
|
11
|
-
|
|
12
|
-
## Code design
|
|
13
|
-
By strictly adhering to object-oriented design (BinaryTree -> BST -> AVLTree -> TreeMultiset), you can seamlessly inherit the existing data structures to implement the customized ones you need. Object-oriented design stands as the optimal approach to data structure design.
|
|
14
5
|
|
|
15
6
|
# How
|
|
16
7
|
|
|
17
8
|
## install
|
|
18
|
-
###
|
|
19
|
-
|
|
9
|
+
### npm
|
|
20
10
|
```bash
|
|
21
|
-
|
|
11
|
+
npm i linked-list-typed
|
|
22
12
|
```
|
|
23
|
-
|
|
24
|
-
### npm
|
|
25
|
-
|
|
13
|
+
### yarn
|
|
26
14
|
```bash
|
|
27
|
-
|
|
15
|
+
yarn add linked-list-typed
|
|
28
16
|
```
|
|
29
17
|
|
|
30
|
-
###
|
|
31
|
-
|
|
18
|
+
### snippet
|
|
32
19
|
#### TS
|
|
33
20
|
```typescript
|
|
34
|
-
import {BST, BSTNode} from 'data-structure-typed';
|
|
35
|
-
|
|
36
|
-
const bst = new BST();
|
|
37
|
-
bst.add(11);
|
|
38
|
-
bst.add(3);
|
|
39
|
-
bst.addMany([15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5]);
|
|
40
|
-
bst.size === 16; // true
|
|
41
|
-
bst.has(6); // true
|
|
42
|
-
const node6 = bst.get(6);
|
|
43
|
-
bst.getHeight(6) === 2; // true
|
|
44
|
-
bst.getHeight() === 5; // true
|
|
45
|
-
bst.getDepth(6) === 3; // true
|
|
46
|
-
const leftMost = bst.getLeftMost();
|
|
47
|
-
leftMost?.id === 1; // true
|
|
48
|
-
expect(leftMost?.id).toBe(1);
|
|
49
|
-
bst.remove(6);
|
|
50
|
-
bst.get(6); // null
|
|
51
|
-
bst.isAVLBalanced(); // true or false
|
|
52
|
-
const bfsIDs = bst.BFS();
|
|
53
|
-
bfsIDs[0] === 11; // true
|
|
54
|
-
expect(bfsIDs[0]).toBe(11);
|
|
55
|
-
|
|
56
|
-
const objBST = new BST<BSTNode<{ id: number, keyA: number }>>();
|
|
57
|
-
objBST.add(11, {id: 11, keyA: 11});
|
|
58
|
-
objBST.add(3, {id: 3, keyA: 3});
|
|
59
|
-
|
|
60
|
-
objBST.addMany([{id: 15, keyA: 15}, {id: 1, keyA: 1}, {id: 8, keyA: 8},
|
|
61
|
-
{id: 13, keyA: 13}, {id: 16, keyA: 16}, {id: 2, keyA: 2},
|
|
62
|
-
{id: 6, keyA: 6}, {id: 9, keyA: 9}, {id: 12, keyA: 12},
|
|
63
|
-
{id: 14, keyA: 14}, {id: 4, keyA: 4}, {id: 7, keyA: 7},
|
|
64
|
-
{id: 10, keyA: 10}, {id: 5, keyA: 5}]);
|
|
65
|
-
|
|
66
|
-
objBST.remove(11);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const avlTree = new AVLTree();
|
|
70
|
-
avlTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5])
|
|
71
|
-
avlTree.isAVLBalanced(); // true
|
|
72
|
-
avlTree.remove(10);
|
|
73
|
-
avlTree.isAVLBalanced(); // true
|
|
74
21
|
|
|
75
22
|
```
|
|
76
23
|
#### JS
|
|
77
24
|
```javascript
|
|
78
|
-
const {BST, BSTNode} = require('data-structure-typed');
|
|
79
|
-
|
|
80
|
-
const bst = new BST();
|
|
81
|
-
bst.add(11);
|
|
82
|
-
bst.add(3);
|
|
83
|
-
bst.addMany([15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5]);
|
|
84
|
-
bst.size === 16; // true
|
|
85
|
-
bst.has(6); // true
|
|
86
|
-
const node6 = bst.get(6);
|
|
87
|
-
bst.getHeight(6) === 2; // true
|
|
88
|
-
bst.getHeight() === 5; // true
|
|
89
|
-
bst.getDepth(6) === 3; // true
|
|
90
|
-
const leftMost = bst.getLeftMost();
|
|
91
|
-
leftMost?.id === 1; // true
|
|
92
|
-
expect(leftMost?.id).toBe(1);
|
|
93
|
-
bst.remove(6);
|
|
94
|
-
bst.get(6); // null
|
|
95
|
-
bst.isAVLBalanced(); // true or false
|
|
96
|
-
const bfsIDs = bst.BFS();
|
|
97
|
-
bfsIDs[0] === 11; // true
|
|
98
|
-
expect(bfsIDs[0]).toBe(11);
|
|
99
|
-
|
|
100
|
-
const objBST = new BST();
|
|
101
|
-
objBST.add(11, {id: 11, keyA: 11});
|
|
102
|
-
objBST.add(3, {id: 3, keyA: 3});
|
|
103
|
-
|
|
104
|
-
objBST.addMany([{id: 15, keyA: 15}, {id: 1, keyA: 1}, {id: 8, keyA: 8},
|
|
105
|
-
{id: 13, keyA: 13}, {id: 16, keyA: 16}, {id: 2, keyA: 2},
|
|
106
|
-
{id: 6, keyA: 6}, {id: 9, keyA: 9}, {id: 12, keyA: 12},
|
|
107
|
-
{id: 14, keyA: 14}, {id: 4, keyA: 4}, {id: 7, keyA: 7},
|
|
108
|
-
{id: 10, keyA: 10}, {id: 5, keyA: 5}]);
|
|
109
|
-
|
|
110
|
-
objBST.remove(11);
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const avlTree = new AVLTree();
|
|
114
|
-
avlTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5])
|
|
115
|
-
avlTree.isAVLBalanced(); // true
|
|
116
|
-
avlTree.remove(10);
|
|
117
|
-
avlTree.isAVLBalanced(); // true
|
|
118
|
-
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
### Directed Graph simple snippet
|
|
122
25
|
|
|
123
|
-
#### TS or JS
|
|
124
|
-
```typescript
|
|
125
|
-
import {DirectedGraph} from 'data-structure-typed';
|
|
126
|
-
|
|
127
|
-
const graph = new DirectedGraph();
|
|
128
|
-
|
|
129
|
-
graph.addVertex('A');
|
|
130
|
-
graph.addVertex('B');
|
|
131
|
-
|
|
132
|
-
graph.hasVertex('A'); // true
|
|
133
|
-
graph.hasVertex('B'); // true
|
|
134
|
-
graph.hasVertex('C'); // false
|
|
135
|
-
|
|
136
|
-
graph.addEdge('A', 'B');
|
|
137
|
-
graph.hasEdge('A', 'B'); // true
|
|
138
|
-
graph.hasEdge('B', 'A'); // false
|
|
139
|
-
|
|
140
|
-
graph.removeEdgeSrcToDest('A', 'B');
|
|
141
|
-
graph.hasEdge('A', 'B'); // false
|
|
142
|
-
|
|
143
|
-
graph.addVertex('C');
|
|
144
|
-
|
|
145
|
-
graph.addEdge('A', 'B');
|
|
146
|
-
graph.addEdge('B', 'C');
|
|
147
|
-
|
|
148
|
-
const topologicalOrderIds = graph.topologicalSort(); // ['A', 'B', 'C']
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
### Undirected Graph snippet
|
|
152
|
-
|
|
153
|
-
#### TS or JS
|
|
154
|
-
```typescript
|
|
155
|
-
import {UndirectedGraph} from 'data-structure-typed';
|
|
156
|
-
|
|
157
|
-
const graph = new UndirectedGraph();
|
|
158
|
-
graph.addVertex('A');
|
|
159
|
-
graph.addVertex('B');
|
|
160
|
-
graph.addVertex('C');
|
|
161
|
-
graph.addVertex('D');
|
|
162
|
-
graph.removeVertex('C');
|
|
163
|
-
graph.addEdge('A', 'B');
|
|
164
|
-
graph.addEdge('B', 'D');
|
|
165
|
-
|
|
166
|
-
const dijkstraResult = graph.dijkstra('A');
|
|
167
|
-
Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id) // ['A', 'B', 'D']
|
|
168
26
|
```
|
|
169
27
|
|
|
170
|
-

|
|
171
|
-
|
|
172
|
-

|
|
173
|
-
|
|
174
|
-

|
|
175
|
-
|
|
176
|
-

|
|
177
|
-
|
|
178
28
|
|
|
179
29
|
## API docs & Examples
|
|
180
30
|
|
|
@@ -182,10 +32,6 @@ import {UndirectedGraph} from 'data-structure-typed';
|
|
|
182
32
|
|
|
183
33
|
[Live Examples](https://data-structure-typed-examples.vercel.app)
|
|
184
34
|
|
|
185
|
-
<a href="https://data-structure-typed-examples.vercel.app" target="_blank">Live Examples</a>
|
|
186
|
-
|
|
187
|
-
[//]: # ([Examples Repository](https://github.com/zrwusa/data-structure-typed-examples))
|
|
188
|
-
|
|
189
35
|
<a href="https://github.com/zrwusa/data-structure-typed-examples" target="_blank">Examples Repository</a>
|
|
190
36
|
|
|
191
37
|
## Data Structures
|
|
@@ -203,10 +49,10 @@ import {UndirectedGraph} from 'data-structure-typed';
|
|
|
203
49
|
<tbody>
|
|
204
50
|
<tr>
|
|
205
51
|
<td>Binary Tree</td>
|
|
206
|
-
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""
|
|
207
|
-
</
|
|
208
|
-
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""
|
|
209
|
-
</
|
|
52
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""/>
|
|
53
|
+
</td>
|
|
54
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""/>
|
|
55
|
+
</td>
|
|
210
56
|
<td><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryTree.html"><span>Binary Tree</span></a></td>
|
|
211
57
|
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
212
58
|
</tr>
|
|
@@ -653,46 +499,6 @@ import {UndirectedGraph} from 'data-structure-typed';
|
|
|
653
499
|
|
|
654
500
|

|
|
655
501
|
|
|
656
|
-
[//]: # ()
|
|
657
|
-
|
|
658
|
-
[//]: # ()
|
|
659
|
-
[//]: # ()
|
|
660
|
-
|
|
661
|
-
[//]: # ()
|
|
662
|
-
[//]: # ()
|
|
663
|
-
|
|
664
|
-
[//]: # ()
|
|
665
|
-
[//]: # ()
|
|
666
|
-
|
|
667
|
-
[//]: # ()
|
|
668
|
-
[//]: # ()
|
|
669
|
-
|
|
670
|
-
[//]: # ()
|
|
671
|
-
[//]: # ()
|
|
672
|
-
|
|
673
|
-
[//]: # ()
|
|
674
|
-
[//]: # ()
|
|
675
|
-
|
|
676
|
-
[//]: # ()
|
|
677
|
-
[//]: # ()
|
|
678
|
-
|
|
679
|
-
[//]: # ()
|
|
680
|
-
[//]: # ()
|
|
681
|
-
|
|
682
|
-
[//]: # ()
|
|
683
|
-
[//]: # ()
|
|
684
|
-
|
|
685
|
-
[//]: # ()
|
|
686
|
-
[//]: # ()
|
|
687
|
-
|
|
688
|
-
[//]: # ()
|
|
689
|
-
[//]: # ()
|
|
690
|
-
|
|
691
|
-
[//]: # ()
|
|
692
|
-
|
|
693
|
-
[//]: # ()
|
|
694
|
-
|
|
695
|
-
[//]: # ()
|
|
696
502
|
|
|
697
503
|
|
|
698
504
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 { DoublyLinkedListNode, DoublyLinkedList, SinglyLinkedListNode, SinglyLinkedList } from 'data-structure-typed';
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
|
|
3
|
+
exports.SinglyLinkedList = exports.SinglyLinkedListNode = 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
|
+
*/
|
|
11
|
+
var data_structure_typed_1 = require("data-structure-typed");
|
|
12
|
+
Object.defineProperty(exports, "DoublyLinkedListNode", { enumerable: true, get: function () { return data_structure_typed_1.DoublyLinkedListNode; } });
|
|
13
|
+
Object.defineProperty(exports, "DoublyLinkedList", { enumerable: true, get: function () { return data_structure_typed_1.DoublyLinkedList; } });
|
|
14
|
+
Object.defineProperty(exports, "SinglyLinkedListNode", { enumerable: true, get: function () { return data_structure_typed_1.SinglyLinkedListNode; } });
|
|
15
|
+
Object.defineProperty(exports, "SinglyLinkedList", { enumerable: true, get: function () { return data_structure_typed_1.SinglyLinkedList; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "linked-list-typed",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.6",
|
|
4
4
|
"description": "Linked List, Doubly Linked List, Singly Linked List. Javascript & Typescript Data Structure.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"typescript": "^4.9.5"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"data-structure-typed": "
|
|
60
|
+
"data-structure-typed": "1.19.6",
|
|
61
61
|
"zod": "^3.22.2"
|
|
62
62
|
}
|
|
63
63
|
}
|
package/tsconfig.json
CHANGED
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
"declaration": true,
|
|
4
4
|
"outDir": "./dist",
|
|
5
5
|
"module": "commonjs",
|
|
6
|
-
"target": "
|
|
6
|
+
"target": "es6",
|
|
7
7
|
"lib": [
|
|
8
|
-
"
|
|
8
|
+
// "es2015",
|
|
9
|
+
"esnext"
|
|
9
10
|
],
|
|
10
11
|
"strict": true,
|
|
11
12
|
"esModuleInterop": true,
|
|
@@ -30,8 +31,9 @@
|
|
|
30
31
|
"src",
|
|
31
32
|
],
|
|
32
33
|
"exclude": [
|
|
33
|
-
// "node_modules/data-structure-typed",
|
|
34
|
+
// "node_modules/data-structure-typed",
|
|
34
35
|
"node_modules",
|
|
35
36
|
"dist"
|
|
36
37
|
]
|
|
37
|
-
}
|
|
38
|
+
}
|
|
39
|
+
|
|
@@ -1,195 +0,0 @@
|
|
|
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 DoublyLinkedListNode<T = number> {
|
|
9
|
-
/**
|
|
10
|
-
* The constructor function initializes the value, next, and previous properties of an object.
|
|
11
|
-
* @param {T} val - The "val" parameter is the value that will be stored in the node. It can be of any data type, as it
|
|
12
|
-
* is defined as a generic type "T".
|
|
13
|
-
*/
|
|
14
|
-
constructor(val: T);
|
|
15
|
-
private _val;
|
|
16
|
-
get val(): T;
|
|
17
|
-
set val(value: T);
|
|
18
|
-
private _next;
|
|
19
|
-
get next(): DoublyLinkedListNode<T> | null;
|
|
20
|
-
set next(value: DoublyLinkedListNode<T> | null);
|
|
21
|
-
private _prev;
|
|
22
|
-
get prev(): DoublyLinkedListNode<T> | null;
|
|
23
|
-
set prev(value: DoublyLinkedListNode<T> | null);
|
|
24
|
-
}
|
|
25
|
-
export declare class DoublyLinkedList<T = number> {
|
|
26
|
-
/**
|
|
27
|
-
* The constructor initializes the linked list with an empty head, tail, and length.
|
|
28
|
-
*/
|
|
29
|
-
constructor();
|
|
30
|
-
private _head;
|
|
31
|
-
get head(): DoublyLinkedListNode<T> | null;
|
|
32
|
-
set head(value: DoublyLinkedListNode<T> | null);
|
|
33
|
-
private _tail;
|
|
34
|
-
get tail(): DoublyLinkedListNode<T> | null;
|
|
35
|
-
set tail(value: DoublyLinkedListNode<T> | null);
|
|
36
|
-
private _length;
|
|
37
|
-
get length(): number;
|
|
38
|
-
/**
|
|
39
|
-
* The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
|
|
40
|
-
* given array.
|
|
41
|
-
* @param {T[]} data - The `data` parameter is an array of elements of type `T`.
|
|
42
|
-
* @returns The `fromArray` function returns a DoublyLinkedList object.
|
|
43
|
-
*/
|
|
44
|
-
static fromArray<T>(data: T[]): DoublyLinkedList<T>;
|
|
45
|
-
/**
|
|
46
|
-
* The push function adds a new node with the given value to the end of the doubly linked list.
|
|
47
|
-
* @param {T} val - The value to be added to the linked list.
|
|
48
|
-
*/
|
|
49
|
-
push(val: T): void;
|
|
50
|
-
/**
|
|
51
|
-
* The `pop()` function removes and returns the value of the last node in a doubly linked list.
|
|
52
|
-
* @returns The method is returning the value of the removed node (removedNode.val) if the list is not empty. If the
|
|
53
|
-
* list is empty, it returns null.
|
|
54
|
-
*/
|
|
55
|
-
pop(): T | null;
|
|
56
|
-
/**
|
|
57
|
-
* The `shift()` function removes and returns the value of the first node in a doubly linked list.
|
|
58
|
-
* @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
|
|
59
|
-
* list.
|
|
60
|
-
*/
|
|
61
|
-
shift(): T | null;
|
|
62
|
-
/**
|
|
63
|
-
* The unshift function adds a new node with the given value to the beginning of a doubly linked list.
|
|
64
|
-
* @param {T} val - The `val` parameter represents the value of the new node that will be added to the beginning of the
|
|
65
|
-
* doubly linked list.
|
|
66
|
-
*/
|
|
67
|
-
unshift(val: T): void;
|
|
68
|
-
/**
|
|
69
|
-
* The `getAt` function returns the value at a specified index in a linked list, or null if the index is out of bounds.
|
|
70
|
-
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
71
|
-
* retrieve from the list.
|
|
72
|
-
* @returns The method is returning the value at the specified index in the linked list. If the index is out of bounds
|
|
73
|
-
* or the linked list is empty, it will return null.
|
|
74
|
-
*/
|
|
75
|
-
getAt(index: number): T | null;
|
|
76
|
-
/**
|
|
77
|
-
* The function `getNodeAt` returns the node at a given index in a doubly linked list, or null if the index is out of
|
|
78
|
-
* range.
|
|
79
|
-
* @param {number} index - The `index` parameter is a number that represents the position of the node we want to
|
|
80
|
-
* retrieve from the doubly linked list. It indicates the zero-based index of the node we want to access.
|
|
81
|
-
* @returns The method `getNodeAt(index: number)` returns a `DoublyLinkedListNode<T>` object if the index is within the
|
|
82
|
-
* valid range of the linked list, otherwise it returns `null`.
|
|
83
|
-
*/
|
|
84
|
-
getNodeAt(index: number): DoublyLinkedListNode<T> | null;
|
|
85
|
-
/**
|
|
86
|
-
* The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
|
|
87
|
-
* node if found, otherwise it returns null.
|
|
88
|
-
* @param {T} val - The `val` parameter is the value that we want to search for in the doubly linked list.
|
|
89
|
-
* @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<T>` if a node with the specified value `val`
|
|
90
|
-
* is found in the linked list. If no such node is found, it returns `null`.
|
|
91
|
-
*/
|
|
92
|
-
findNode(val: T): DoublyLinkedListNode<T> | null;
|
|
93
|
-
/**
|
|
94
|
-
* The `insert` function inserts a value at a specified index in a doubly linked list.
|
|
95
|
-
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
96
|
-
* DoublyLinkedList. It is of type number.
|
|
97
|
-
* @param {T} val - The `val` parameter represents the value that you want to insert into the Doubly 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: T): boolean;
|
|
103
|
-
/**
|
|
104
|
-
* The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
|
|
105
|
-
* @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
|
|
106
|
-
* data structure. It is of type number.
|
|
107
|
-
* @returns The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of
|
|
108
|
-
* bounds.
|
|
109
|
-
*/
|
|
110
|
-
deleteAt(index: number): T | null;
|
|
111
|
-
delete(valOrNode: T): boolean;
|
|
112
|
-
delete(valOrNode: DoublyLinkedListNode<T>): boolean;
|
|
113
|
-
/**
|
|
114
|
-
* The `toArray` function converts a linked list into an array.
|
|
115
|
-
* @returns The `toArray()` method is returning an array of type `T[]`.
|
|
116
|
-
*/
|
|
117
|
-
toArray(): T[];
|
|
118
|
-
/**
|
|
119
|
-
* The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively.
|
|
120
|
-
*/
|
|
121
|
-
clear(): void;
|
|
122
|
-
/**
|
|
123
|
-
* The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
|
|
124
|
-
* @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This
|
|
125
|
-
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
|
|
126
|
-
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
|
|
127
|
-
* the callback function. If no element satisfies the condition, it returns `null`.
|
|
128
|
-
*/
|
|
129
|
-
find(callback: (val: T) => boolean): T | null;
|
|
130
|
-
/**
|
|
131
|
-
* The function returns the index of the first occurrence of a given value in a linked list.
|
|
132
|
-
* @param {T} val - The parameter `val` is of type `T`, which means it can be any data type. It represents the value
|
|
133
|
-
* that we are searching for in the linked list.
|
|
134
|
-
* @returns The method `indexOf` returns the index of the first occurrence of the specified value `val` in the linked
|
|
135
|
-
* list. If the value is not found, it returns -1.
|
|
136
|
-
*/
|
|
137
|
-
indexOf(val: T): number;
|
|
138
|
-
/**
|
|
139
|
-
* The `findLast` function iterates through a linked list from the last node to the first node and returns the last
|
|
140
|
-
* value that satisfies the given callback function, or null if no value satisfies the callback.
|
|
141
|
-
* @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This
|
|
142
|
-
* function is used to determine whether a given value satisfies a certain condition.
|
|
143
|
-
* @returns The method `findLast` returns the last value in the linked list that satisfies the condition specified by
|
|
144
|
-
* the callback function. If no value satisfies the condition, it returns `null`.
|
|
145
|
-
*/
|
|
146
|
-
findLast(callback: (val: T) => boolean): T | null;
|
|
147
|
-
/**
|
|
148
|
-
* The `toArrayReverse` function converts a doubly linked list into an array in reverse order.
|
|
149
|
-
* @returns The `toArrayReverse()` function returns an array of type `T[]`.
|
|
150
|
-
*/
|
|
151
|
-
toArrayReverse(): T[];
|
|
152
|
-
/**
|
|
153
|
-
* The `reverse` function reverses the order of the elements in a doubly linked list.
|
|
154
|
-
*/
|
|
155
|
-
reverse(): void;
|
|
156
|
-
/**
|
|
157
|
-
* The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
|
|
158
|
-
* @param callback - The callback parameter is a function that takes two arguments: val and index. The val argument
|
|
159
|
-
* represents the value of the current node in the linked list, and the index argument represents the index of the
|
|
160
|
-
* current node in the linked list.
|
|
161
|
-
*/
|
|
162
|
-
forEach(callback: (val: T, index: number) => void): void;
|
|
163
|
-
/**
|
|
164
|
-
* The `map` function takes a callback function and applies it to each element in the DoublyLinkedList, returning a new
|
|
165
|
-
* DoublyLinkedList with the transformed values.
|
|
166
|
-
* @param callback - The callback parameter is a function that takes a value of type T (the type of values stored in
|
|
167
|
-
* the original DoublyLinkedList) and returns a value of type U (the type of values that will be stored in the mapped
|
|
168
|
-
* DoublyLinkedList).
|
|
169
|
-
* @returns The `map` function is returning a new instance of `DoublyLinkedList<U>` that contains the mapped values.
|
|
170
|
-
*/
|
|
171
|
-
map<U>(callback: (val: T) => U): DoublyLinkedList<U>;
|
|
172
|
-
/**
|
|
173
|
-
* The `filter` function iterates through a DoublyLinkedList and returns a new DoublyLinkedList containing only the
|
|
174
|
-
* elements that satisfy the given callback function.
|
|
175
|
-
* @param callback - The `callback` parameter is a function that takes a value of type `T` and returns a boolean value.
|
|
176
|
-
* It is used to determine whether a value should be included in the filtered list or not.
|
|
177
|
-
* @returns The filtered list, which is an instance of the DoublyLinkedList class.
|
|
178
|
-
*/
|
|
179
|
-
filter(callback: (val: T) => boolean): DoublyLinkedList<T>;
|
|
180
|
-
/**
|
|
181
|
-
* The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
|
|
182
|
-
* single value.
|
|
183
|
-
* @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `val`. It is
|
|
184
|
-
* used to perform a specific operation on each element of the linked list.
|
|
185
|
-
* @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
|
|
186
|
-
* point for the reduction operation.
|
|
187
|
-
* @returns The `reduce` method is returning the final value of the accumulator after iterating through all the
|
|
188
|
-
* elements in the linked list.
|
|
189
|
-
*/
|
|
190
|
-
reduce<U>(callback: (accumulator: U, val: T) => U, initialValue: U): U;
|
|
191
|
-
insertAfter(existingValueOrNode: T, newValue: T): boolean;
|
|
192
|
-
insertAfter(existingValueOrNode: DoublyLinkedListNode<T>, newValue: T): boolean;
|
|
193
|
-
insertBefore(existingValueOrNode: T, newValue: T): boolean;
|
|
194
|
-
insertBefore(existingValueOrNode: DoublyLinkedListNode<T>, newValue: T): boolean;
|
|
195
|
-
}
|