data-structure-typed 2.5.0 → 2.5.2
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/.vitepress/cache/deps_temp_51f5f1b0/chunk-7OIKW5WK.js +12984 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/package.json +3 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vue_devtools-api.js +4505 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vueuse_core.js +9731 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/vue.js +347 -0
- package/CHANGELOG.md +5 -1
- package/README.md +124 -29
- package/dist/cjs/binary-tree.cjs +26282 -0
- package/dist/cjs/graph.cjs +5422 -0
- package/dist/cjs/hash.cjs +1310 -0
- package/dist/cjs/heap.cjs +1602 -0
- package/dist/cjs/index.cjs +31257 -14673
- package/dist/cjs/linked-list.cjs +4576 -0
- package/dist/cjs/matrix.cjs +1080 -0
- package/dist/cjs/priority-queue.cjs +1376 -0
- package/dist/cjs/queue.cjs +4264 -0
- package/dist/cjs/stack.cjs +907 -0
- package/dist/cjs/trie.cjs +1223 -0
- package/dist/cjs-legacy/binary-tree.cjs +26319 -0
- package/dist/cjs-legacy/graph.cjs +5420 -0
- package/dist/cjs-legacy/hash.cjs +1310 -0
- package/dist/cjs-legacy/heap.cjs +1599 -0
- package/dist/cjs-legacy/index.cjs +31268 -14679
- package/dist/cjs-legacy/linked-list.cjs +4582 -0
- package/dist/cjs-legacy/matrix.cjs +1083 -0
- package/dist/cjs-legacy/priority-queue.cjs +1374 -0
- package/dist/cjs-legacy/queue.cjs +4262 -0
- package/dist/cjs-legacy/stack.cjs +907 -0
- package/dist/cjs-legacy/trie.cjs +1222 -0
- package/dist/esm/binary-tree.mjs +26267 -0
- package/dist/esm/graph.mjs +5409 -0
- package/dist/esm/hash.mjs +1307 -0
- package/dist/esm/heap.mjs +1596 -0
- package/dist/esm/index.mjs +31254 -14674
- package/dist/esm/linked-list.mjs +4569 -0
- package/dist/esm/matrix.mjs +1076 -0
- package/dist/esm/priority-queue.mjs +1372 -0
- package/dist/esm/queue.mjs +4260 -0
- package/dist/esm/stack.mjs +905 -0
- package/dist/esm/trie.mjs +1220 -0
- package/dist/esm-legacy/binary-tree.mjs +26304 -0
- package/dist/esm-legacy/graph.mjs +5407 -0
- package/dist/esm-legacy/hash.mjs +1307 -0
- package/dist/esm-legacy/heap.mjs +1593 -0
- package/dist/esm-legacy/index.mjs +31265 -14680
- package/dist/esm-legacy/linked-list.mjs +4575 -0
- package/dist/esm-legacy/matrix.mjs +1079 -0
- package/dist/esm-legacy/priority-queue.mjs +1370 -0
- package/dist/esm-legacy/queue.mjs +4258 -0
- package/dist/esm-legacy/stack.mjs +905 -0
- package/dist/esm-legacy/trie.mjs +1219 -0
- package/dist/types/common/error.d.ts +9 -0
- package/dist/types/common/index.d.ts +1 -1
- package/dist/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
- package/dist/types/data-structures/base/linear-base.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +288 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +336 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +618 -18
- package/dist/types/data-structures/binary-tree/bst.d.ts +676 -1
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +456 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +144 -1
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +3307 -399
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3285 -360
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2674 -325
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +3072 -287
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/types/data-structures/graph/directed-graph.d.ts +240 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +216 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +274 -10
- package/dist/types/data-structures/heap/heap.d.ts +336 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +411 -3
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +363 -3
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +434 -2
- package/dist/types/data-structures/matrix/matrix.d.ts +192 -0
- package/dist/types/data-structures/queue/deque.d.ts +364 -4
- package/dist/types/data-structures/queue/queue.d.ts +288 -0
- package/dist/types/data-structures/stack/stack.d.ts +240 -0
- package/dist/types/data-structures/trie/trie.d.ts +292 -4
- package/dist/types/interfaces/graph.d.ts +1 -1
- package/dist/types/types/common.d.ts +2 -2
- package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
- package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
- package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
- package/dist/types/types/utils/validate-type.d.ts +4 -4
- package/dist/umd/data-structure-typed.js +31196 -14608
- package/dist/umd/data-structure-typed.min.js +11 -5
- package/docs-site-docusaurus/README.md +41 -0
- package/docs-site-docusaurus/docs/api/README.md +52 -0
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +6644 -0
- package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +282 -0
- package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +2266 -0
- package/docs-site-docusaurus/docs/api/classes/BST.md +6293 -0
- package/docs-site-docusaurus/docs/api/classes/BSTNode.md +333 -0
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +455 -0
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +4647 -0
- package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +331 -0
- package/docs-site-docusaurus/docs/api/classes/Deque.md +2767 -0
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +2999 -0
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +2685 -0
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +221 -0
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +253 -0
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +21 -0
- package/docs-site-docusaurus/docs/api/classes/HashMap.md +1333 -0
- package/docs-site-docusaurus/docs/api/classes/Heap.md +1881 -0
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +800 -0
- package/docs-site-docusaurus/docs/api/classes/IterableEntryBase.md +644 -0
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +1632 -0
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +1853 -0
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +1108 -0
- package/docs-site-docusaurus/docs/api/classes/LinkedListNode.md +156 -0
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +2824 -0
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +2929 -0
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +1026 -0
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +1866 -0
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +1883 -0
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +1879 -0
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +1882 -0
- package/docs-site-docusaurus/docs/api/classes/Navigator.md +109 -0
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +1839 -0
- package/docs-site-docusaurus/docs/api/classes/Queue.md +2244 -0
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +6888 -0
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +372 -0
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +2897 -0
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +169 -0
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +1229 -0
- package/docs-site-docusaurus/docs/api/classes/Stack.md +1573 -0
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +1389 -0
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +1591 -0
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +1246 -0
- package/docs-site-docusaurus/docs/api/classes/Trie.md +1708 -0
- package/docs-site-docusaurus/docs/api/classes/TrieNode.md +199 -0
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +2979 -0
- package/docs-site-docusaurus/docs/guide/_category_.json +6 -0
- package/docs-site-docusaurus/docs/guide/architecture.md +615 -0
- package/docs-site-docusaurus/docs/guide/concepts.md +451 -0
- package/docs-site-docusaurus/docs/guide/faq.md +180 -0
- package/docs-site-docusaurus/docs/guide/guides.md +597 -0
- package/docs-site-docusaurus/docs/guide/installation.md +62 -0
- package/docs-site-docusaurus/docs/guide/integrations.md +825 -0
- package/docs-site-docusaurus/docs/guide/overview.md +645 -0
- package/docs-site-docusaurus/docs/guide/performance.md +835 -0
- package/docs-site-docusaurus/docs/guide/quick-start.md +104 -0
- package/docs-site-docusaurus/docs/guide/use-cases/_category_.json +6 -0
- package/docs-site-docusaurus/docs/guide/use-cases/array-sort-alternative.md +158 -0
- package/docs-site-docusaurus/docs/guide/use-cases/heap-vs-sorting.md +92 -0
- package/docs-site-docusaurus/docs/guide/use-cases/map-vs-treemap.md +151 -0
- package/docs-site-docusaurus/docs/guide/use-cases/priority-queue-typescript.md +113 -0
- package/docs-site-docusaurus/docs/guide/use-cases/treemap-javascript.md +151 -0
- package/docs-site-docusaurus/docusaurus.config.ts +159 -0
- package/docs-site-docusaurus/fix-mdx-generics.mjs +75 -0
- package/docs-site-docusaurus/package-lock.json +18667 -0
- package/docs-site-docusaurus/package.json +50 -0
- package/docs-site-docusaurus/prefix-class-to-methods.mjs +48 -0
- package/docs-site-docusaurus/sidebars.ts +23 -0
- package/docs-site-docusaurus/sort-protected.mjs +87 -0
- package/docs-site-docusaurus/src/css/custom.css +96 -0
- package/docs-site-docusaurus/src/pages/index.module.css +13 -0
- package/docs-site-docusaurus/src/pages/index.tsx +120 -0
- package/docs-site-docusaurus/src/pages/markdown-page.md +7 -0
- package/docs-site-docusaurus/src/theme/TOCItems/index.tsx +34 -0
- package/docs-site-docusaurus/static/.nojekyll +0 -0
- package/docs-site-docusaurus/static/img/docusaurus-social-card.jpg +0 -0
- package/docs-site-docusaurus/static/img/docusaurus.png +0 -0
- package/docs-site-docusaurus/static/img/favicon.ico +0 -0
- package/docs-site-docusaurus/static/img/favicon.png +0 -0
- package/docs-site-docusaurus/static/img/logo-180.png +0 -0
- package/docs-site-docusaurus/static/img/logo.jpg +0 -0
- package/docs-site-docusaurus/static/img/logo.png +0 -0
- package/docs-site-docusaurus/static/img/logo.svg +1 -0
- package/docs-site-docusaurus/static/img/og-image.png +0 -0
- package/docs-site-docusaurus/static/img/undraw_docusaurus_mountain.svg +171 -0
- package/docs-site-docusaurus/static/img/undraw_docusaurus_react.svg +170 -0
- package/docs-site-docusaurus/static/img/undraw_docusaurus_tree.svg +40 -0
- package/docs-site-docusaurus/static/llms.txt +37 -0
- package/docs-site-docusaurus/static/robots.txt +4 -0
- package/docs-site-docusaurus/typedoc.json +23 -0
- package/llms.txt +37 -0
- package/package.json +159 -55
- package/src/common/error.ts +19 -1
- package/src/common/index.ts +1 -1
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-element-base.ts +3 -2
- package/src/data-structures/base/iterable-entry-base.ts +8 -8
- package/src/data-structures/base/linear-base.ts +3 -3
- package/src/data-structures/binary-tree/avl-tree.ts +287 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +327 -5
- package/src/data-structures/binary-tree/binary-tree.ts +581 -6
- package/src/data-structures/binary-tree/bst.ts +922 -7
- package/src/data-structures/binary-tree/red-black-tree.ts +453 -0
- package/src/data-structures/binary-tree/segment-tree.ts +139 -2
- package/src/data-structures/binary-tree/tree-map.ts +3300 -495
- package/src/data-structures/binary-tree/tree-multi-map.ts +3384 -563
- package/src/data-structures/binary-tree/tree-multi-set.ts +2757 -493
- package/src/data-structures/binary-tree/tree-set.ts +3122 -440
- package/src/data-structures/graph/abstract-graph.ts +6 -6
- package/src/data-structures/graph/directed-graph.ts +230 -0
- package/src/data-structures/graph/undirected-graph.ts +207 -0
- package/src/data-structures/hash/hash-map.ts +270 -19
- package/src/data-structures/heap/heap.ts +326 -4
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +394 -3
- package/src/data-structures/linked-list/singly-linked-list.ts +348 -3
- package/src/data-structures/linked-list/skip-linked-list.ts +421 -7
- package/src/data-structures/matrix/matrix.ts +194 -10
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +350 -5
- package/src/data-structures/queue/queue.ts +276 -0
- package/src/data-structures/stack/stack.ts +230 -0
- package/src/data-structures/trie/trie.ts +283 -7
- package/src/interfaces/graph.ts +1 -1
- package/src/types/common.ts +2 -2
- package/src/types/data-structures/binary-tree/bst.ts +1 -0
- package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
- package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
- package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
- package/src/types/data-structures/heap/heap.ts +1 -0
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
- package/src/types/utils/validate-type.ts +4 -4
- package/vercel.json +6 -0
- package/dist/leetcode/avl-tree-counter.mjs +0 -2957
- package/dist/leetcode/avl-tree-multi-map.mjs +0 -2889
- package/dist/leetcode/avl-tree.mjs +0 -2720
- package/dist/leetcode/binary-tree.mjs +0 -1594
- package/dist/leetcode/bst.mjs +0 -2398
- package/dist/leetcode/deque.mjs +0 -683
- package/dist/leetcode/directed-graph.mjs +0 -1733
- package/dist/leetcode/doubly-linked-list.mjs +0 -709
- package/dist/leetcode/hash-map.mjs +0 -493
- package/dist/leetcode/heap.mjs +0 -542
- package/dist/leetcode/max-heap.mjs +0 -375
- package/dist/leetcode/max-priority-queue.mjs +0 -383
- package/dist/leetcode/min-heap.mjs +0 -363
- package/dist/leetcode/min-priority-queue.mjs +0 -371
- package/dist/leetcode/priority-queue.mjs +0 -363
- package/dist/leetcode/queue.mjs +0 -943
- package/dist/leetcode/red-black-tree.mjs +0 -2765
- package/dist/leetcode/singly-linked-list.mjs +0 -754
- package/dist/leetcode/stack.mjs +0 -217
- package/dist/leetcode/tree-counter.mjs +0 -3039
- package/dist/leetcode/tree-multi-map.mjs +0 -2913
- package/dist/leetcode/trie.mjs +0 -413
- package/dist/leetcode/undirected-graph.mjs +0 -1650
|
@@ -0,0 +1,2897 @@
|
|
|
1
|
+
[**data-structure-typed**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[data-structure-typed](../README.md) / SinglyLinkedList
|
|
6
|
+
|
|
7
|
+
# Class: SinglyLinkedList\<E, R\>
|
|
8
|
+
|
|
9
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:194](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L194)
|
|
10
|
+
|
|
11
|
+
Singly linked list with O(1) push/pop-like ends operations and linear scans.
|
|
12
|
+
|
|
13
|
+
## Remarks
|
|
14
|
+
|
|
15
|
+
Time O(1), Space O(1)
|
|
16
|
+
|
|
17
|
+
## Examples
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
// SinglyLinkedList for sequentially processed data stream
|
|
21
|
+
interface LogEntry {
|
|
22
|
+
timestamp: number;
|
|
23
|
+
level: 'INFO' | 'WARN' | 'ERROR';
|
|
24
|
+
message: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// SinglyLinkedList is ideal for sequential processing where you only need forward iteration
|
|
28
|
+
// O(1) insertion/deletion at head, O(n) for tail operations
|
|
29
|
+
const logStream = new SinglyLinkedList<LogEntry>();
|
|
30
|
+
|
|
31
|
+
// Simulate incoming log entries
|
|
32
|
+
const entries: LogEntry[] = [
|
|
33
|
+
{ timestamp: 1000, level: 'INFO', message: 'Server started' },
|
|
34
|
+
{ timestamp: 1100, level: 'WARN', message: 'Memory usage high' },
|
|
35
|
+
{ timestamp: 1200, level: 'ERROR', message: 'Connection failed' },
|
|
36
|
+
{ timestamp: 1300, level: 'INFO', message: 'Connection restored' }
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
// Add entries to the stream
|
|
40
|
+
for (const entry of entries) {
|
|
41
|
+
logStream.push(entry);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
console.log(logStream.length); // 4;
|
|
45
|
+
|
|
46
|
+
// Process logs sequentially (only forward iteration needed)
|
|
47
|
+
const processedLogs: string[] = [];
|
|
48
|
+
for (const log of logStream) {
|
|
49
|
+
processedLogs.push(`[${log.level}] ${log.message}`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
console.log(processedLogs); // [
|
|
53
|
+
// '[INFO] Server started',
|
|
54
|
+
// '[WARN] Memory usage high',
|
|
55
|
+
// '[ERROR] Connection failed',
|
|
56
|
+
// '[INFO] Connection restored'
|
|
57
|
+
// ];
|
|
58
|
+
|
|
59
|
+
// Get first log (O(1) - direct head access)
|
|
60
|
+
const firstLog = logStream.at(0);
|
|
61
|
+
console.log(firstLog?.message); // 'Server started';
|
|
62
|
+
|
|
63
|
+
// Remove oldest log (O(1) operation at head)
|
|
64
|
+
const removed = logStream.shift();
|
|
65
|
+
console.log(removed?.message); // 'Server started';
|
|
66
|
+
console.log(logStream.length); // 3;
|
|
67
|
+
|
|
68
|
+
// Remaining logs still maintain order for sequential processing
|
|
69
|
+
console.log(logStream.length); // 3;
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
// implementation of a basic text editor
|
|
74
|
+
class TextEditor {
|
|
75
|
+
private content: SinglyLinkedList<string>;
|
|
76
|
+
private cursorIndex: number;
|
|
77
|
+
private undoStack: Stack<{ operation: string; data?: any }>;
|
|
78
|
+
|
|
79
|
+
constructor() {
|
|
80
|
+
this.content = new SinglyLinkedList<string>();
|
|
81
|
+
this.cursorIndex = 0; // Cursor starts at the beginning
|
|
82
|
+
this.undoStack = new Stack<{ operation: string; data?: any }>(); // Stack to keep track of operations for undo
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
insert(char: string) {
|
|
86
|
+
this.content.addAt(this.cursorIndex, char);
|
|
87
|
+
this.cursorIndex++;
|
|
88
|
+
this.undoStack.push({ operation: 'insert', data: { index: this.cursorIndex - 1 } });
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
delete() {
|
|
92
|
+
if (this.cursorIndex === 0) return; // Nothing to delete
|
|
93
|
+
const deleted = this.content.deleteAt(this.cursorIndex - 1);
|
|
94
|
+
this.cursorIndex--;
|
|
95
|
+
this.undoStack.push({ operation: 'delete', data: { index: this.cursorIndex, char: deleted } });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
moveCursor(index: number) {
|
|
99
|
+
this.cursorIndex = Math.max(0, Math.min(index, this.content.length));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
undo() {
|
|
103
|
+
if (this.undoStack.size === 0) return; // No operations to undo
|
|
104
|
+
const lastAction = this.undoStack.pop();
|
|
105
|
+
|
|
106
|
+
if (lastAction!.operation === 'insert') {
|
|
107
|
+
this.content.deleteAt(lastAction!.data.index);
|
|
108
|
+
this.cursorIndex = lastAction!.data.index;
|
|
109
|
+
} else if (lastAction!.operation === 'delete') {
|
|
110
|
+
this.content.addAt(lastAction!.data.index, lastAction!.data.char);
|
|
111
|
+
this.cursorIndex = lastAction!.data.index + 1;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
getText(): string {
|
|
116
|
+
return [...this.content].join('');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Example Usage
|
|
121
|
+
const editor = new TextEditor();
|
|
122
|
+
editor.insert('H');
|
|
123
|
+
editor.insert('e');
|
|
124
|
+
editor.insert('l');
|
|
125
|
+
editor.insert('l');
|
|
126
|
+
editor.insert('o');
|
|
127
|
+
console.log(editor.getText()); // 'Hello'; // Output: "Hello"
|
|
128
|
+
|
|
129
|
+
editor.delete();
|
|
130
|
+
console.log(editor.getText()); // 'Hell'; // Output: "Hell"
|
|
131
|
+
|
|
132
|
+
editor.undo();
|
|
133
|
+
console.log(editor.getText()); // 'Hello'; // Output: "Hello"
|
|
134
|
+
|
|
135
|
+
editor.moveCursor(1);
|
|
136
|
+
editor.insert('a');
|
|
137
|
+
console.log(editor.getText()); // 'Haello';
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
// Find first matching element
|
|
142
|
+
const list = new SinglyLinkedList<number>([1, 2, 3, 4, 5]);
|
|
143
|
+
console.log(list.find(n => n > 3)); // 4;
|
|
144
|
+
console.log(list.find(n => n > 10)); // undefined;
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
// Iterate over elements
|
|
149
|
+
const list = new SinglyLinkedList<number>([10, 20, 30]);
|
|
150
|
+
const result: number[] = [];
|
|
151
|
+
list.forEach(n => result.push(n));
|
|
152
|
+
console.log(result); // [10, 20, 30];
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Extends
|
|
156
|
+
|
|
157
|
+
- [`LinearLinkedBase`](LinearLinkedBase.md)\<`E`, `R`, [`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\>\>
|
|
158
|
+
|
|
159
|
+
## Extended by
|
|
160
|
+
|
|
161
|
+
- [`LinkedListQueue`](LinkedListQueue.md)
|
|
162
|
+
|
|
163
|
+
## Type Parameters
|
|
164
|
+
|
|
165
|
+
### E
|
|
166
|
+
|
|
167
|
+
`E` = `any`
|
|
168
|
+
|
|
169
|
+
### R
|
|
170
|
+
|
|
171
|
+
`R` = `any`
|
|
172
|
+
|
|
173
|
+
1. Node Structure: Each node contains three parts: a data field, a pointer (or reference) to the previous node, and a pointer to the next node. This structure allows traversal of the linked list in both directions.
|
|
174
|
+
2. Bidirectional Traversal: Unlike doubly linked lists, singly linked lists can be easily traversed forwards but not backwards.
|
|
175
|
+
3. No Centralized Index: Unlike arrays, elements in a linked list are not stored contiguously, so there is no centralized index. Accessing elements in a linked list typically requires traversing from the head or tail node.
|
|
176
|
+
4. High Efficiency in Insertion and Deletion: Adding or removing elements in a linked list does not require moving other elements, making these operations more efficient than in arrays.
|
|
177
|
+
Caution: Although our linked list classes provide methods such as at, setAt, addAt, and indexOf that are based on array indices, their time complexity, like that of the native Array.lastIndexOf, is 𝑂(𝑛). If you need to use these methods frequently, you might want to consider other data structures, such as Deque or Queue (designed for random access). Similarly, since the native Array.shift method has a time complexity of 𝑂(𝑛), using an array to simulate a queue can be inefficient. In such cases, you should use Queue or Deque, as these data structures leverage deferred array rearrangement, effectively reducing the average time complexity to 𝑂(1).
|
|
178
|
+
|
|
179
|
+
## Constructors
|
|
180
|
+
|
|
181
|
+
### Constructor
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
new SinglyLinkedList<E, R>(elements?, options?): SinglyLinkedList<E, R>;
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:205](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L205)
|
|
188
|
+
|
|
189
|
+
Create a SinglyLinkedList and optionally bulk-insert elements.
|
|
190
|
+
|
|
191
|
+
#### Parameters
|
|
192
|
+
|
|
193
|
+
##### elements?
|
|
194
|
+
|
|
195
|
+
\| `Iterable`\<`E`, `any`, `any`\>
|
|
196
|
+
\| `Iterable`\<`R`, `any`, `any`\>
|
|
197
|
+
\| `Iterable`\<[`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\>, `any`, `any`\>
|
|
198
|
+
|
|
199
|
+
Iterable of elements or nodes (or raw records if toElementFn is provided).
|
|
200
|
+
|
|
201
|
+
##### options?
|
|
202
|
+
|
|
203
|
+
`SinglyLinkedListOptions`\<`E`, `R`\>
|
|
204
|
+
|
|
205
|
+
Options such as maxLen and toElementFn.
|
|
206
|
+
|
|
207
|
+
#### Returns
|
|
208
|
+
|
|
209
|
+
`SinglyLinkedList`\<`E`, `R`\>
|
|
210
|
+
|
|
211
|
+
New SinglyLinkedList instance.
|
|
212
|
+
|
|
213
|
+
#### Remarks
|
|
214
|
+
|
|
215
|
+
Time O(N), Space O(N)
|
|
216
|
+
|
|
217
|
+
#### Overrides
|
|
218
|
+
|
|
219
|
+
```ts
|
|
220
|
+
LinearLinkedBase<E, R, SinglyLinkedListNode<E>>.constructor
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## Properties
|
|
224
|
+
|
|
225
|
+
### first
|
|
226
|
+
|
|
227
|
+
#### Get Signature
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
get first(): E | undefined;
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:255](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L255)
|
|
234
|
+
|
|
235
|
+
Get the first element value.
|
|
236
|
+
|
|
237
|
+
##### Remarks
|
|
238
|
+
|
|
239
|
+
Time O(1), Space O(1)
|
|
240
|
+
|
|
241
|
+
##### Returns
|
|
242
|
+
|
|
243
|
+
`E` \| `undefined`
|
|
244
|
+
|
|
245
|
+
First element or undefined.
|
|
246
|
+
|
|
247
|
+
***
|
|
248
|
+
|
|
249
|
+
### head
|
|
250
|
+
|
|
251
|
+
#### Get Signature
|
|
252
|
+
|
|
253
|
+
```ts
|
|
254
|
+
get head(): SinglyLinkedListNode<E> | undefined;
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:221](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L221)
|
|
258
|
+
|
|
259
|
+
Get the head node.
|
|
260
|
+
|
|
261
|
+
##### Remarks
|
|
262
|
+
|
|
263
|
+
Time O(1), Space O(1)
|
|
264
|
+
|
|
265
|
+
##### Returns
|
|
266
|
+
|
|
267
|
+
[`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\> \| `undefined`
|
|
268
|
+
|
|
269
|
+
Head node or undefined.
|
|
270
|
+
|
|
271
|
+
***
|
|
272
|
+
|
|
273
|
+
### last
|
|
274
|
+
|
|
275
|
+
#### Get Signature
|
|
276
|
+
|
|
277
|
+
```ts
|
|
278
|
+
get last(): E | undefined;
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:265](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L265)
|
|
282
|
+
|
|
283
|
+
Get the last element value.
|
|
284
|
+
|
|
285
|
+
##### Remarks
|
|
286
|
+
|
|
287
|
+
Time O(1), Space O(1)
|
|
288
|
+
|
|
289
|
+
##### Returns
|
|
290
|
+
|
|
291
|
+
`E` \| `undefined`
|
|
292
|
+
|
|
293
|
+
Last element or undefined.
|
|
294
|
+
|
|
295
|
+
***
|
|
296
|
+
|
|
297
|
+
### length
|
|
298
|
+
|
|
299
|
+
#### Get Signature
|
|
300
|
+
|
|
301
|
+
```ts
|
|
302
|
+
get length(): number;
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:245](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L245)
|
|
306
|
+
|
|
307
|
+
Get the number of elements.
|
|
308
|
+
|
|
309
|
+
##### Remarks
|
|
310
|
+
|
|
311
|
+
Time O(1), Space O(1)
|
|
312
|
+
|
|
313
|
+
##### Returns
|
|
314
|
+
|
|
315
|
+
`number`
|
|
316
|
+
|
|
317
|
+
Current length.
|
|
318
|
+
|
|
319
|
+
#### Overrides
|
|
320
|
+
|
|
321
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`length`](LinearLinkedBase.md#length)
|
|
322
|
+
|
|
323
|
+
***
|
|
324
|
+
|
|
325
|
+
### maxLen
|
|
326
|
+
|
|
327
|
+
#### Get Signature
|
|
328
|
+
|
|
329
|
+
```ts
|
|
330
|
+
get maxLen(): number;
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
Defined in: [data-structures/base/linear-base.ts:100](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/linear-base.ts#L100)
|
|
334
|
+
|
|
335
|
+
Upper bound for length (if positive), or `-1` when unbounded.
|
|
336
|
+
|
|
337
|
+
##### Remarks
|
|
338
|
+
|
|
339
|
+
Time O(1), Space O(1)
|
|
340
|
+
|
|
341
|
+
##### Returns
|
|
342
|
+
|
|
343
|
+
`number`
|
|
344
|
+
|
|
345
|
+
Maximum allowed length.
|
|
346
|
+
|
|
347
|
+
#### Inherited from
|
|
348
|
+
|
|
349
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`maxLen`](LinearLinkedBase.md#maxlen)
|
|
350
|
+
|
|
351
|
+
***
|
|
352
|
+
|
|
353
|
+
### tail
|
|
354
|
+
|
|
355
|
+
#### Get Signature
|
|
356
|
+
|
|
357
|
+
```ts
|
|
358
|
+
get tail(): SinglyLinkedListNode<E> | undefined;
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:233](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L233)
|
|
362
|
+
|
|
363
|
+
Get the tail node.
|
|
364
|
+
|
|
365
|
+
##### Remarks
|
|
366
|
+
|
|
367
|
+
Time O(1), Space O(1)
|
|
368
|
+
|
|
369
|
+
##### Returns
|
|
370
|
+
|
|
371
|
+
[`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\> \| `undefined`
|
|
372
|
+
|
|
373
|
+
Tail node or undefined.
|
|
374
|
+
|
|
375
|
+
***
|
|
376
|
+
|
|
377
|
+
### toElementFn
|
|
378
|
+
|
|
379
|
+
#### Get Signature
|
|
380
|
+
|
|
381
|
+
```ts
|
|
382
|
+
get toElementFn(): ((rawElement) => E) | undefined;
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
Defined in: [data-structures/base/iterable-element-base.ts:48](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L48)
|
|
386
|
+
|
|
387
|
+
Exposes the current `toElementFn`, if configured.
|
|
388
|
+
|
|
389
|
+
##### Remarks
|
|
390
|
+
|
|
391
|
+
Time O(1), Space O(1).
|
|
392
|
+
|
|
393
|
+
##### Returns
|
|
394
|
+
|
|
395
|
+
((`rawElement`) => `E`) \| `undefined`
|
|
396
|
+
|
|
397
|
+
The converter function or `undefined` when not set.
|
|
398
|
+
|
|
399
|
+
#### Inherited from
|
|
400
|
+
|
|
401
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`toElementFn`](LinearLinkedBase.md#toelementfn)
|
|
402
|
+
|
|
403
|
+
## Methods
|
|
404
|
+
|
|
405
|
+
### \[iterator\]()
|
|
406
|
+
|
|
407
|
+
```ts
|
|
408
|
+
iterator: IterableIterator<E>;
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
Defined in: [data-structures/base/iterable-element-base.ts:61](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L61)
|
|
412
|
+
|
|
413
|
+
Returns an iterator over the structure's elements.
|
|
414
|
+
|
|
415
|
+
#### Parameters
|
|
416
|
+
|
|
417
|
+
##### args
|
|
418
|
+
|
|
419
|
+
...`unknown`[]
|
|
420
|
+
|
|
421
|
+
Optional iterator arguments forwarded to the internal iterator.
|
|
422
|
+
|
|
423
|
+
#### Returns
|
|
424
|
+
|
|
425
|
+
`IterableIterator`\<`E`\>
|
|
426
|
+
|
|
427
|
+
An `IterableIterator<E>` that yields the elements in traversal order.
|
|
428
|
+
|
|
429
|
+
#### Remarks
|
|
430
|
+
|
|
431
|
+
Producing the iterator is O(1); consuming the entire iterator is Time O(n) with O(1) extra space.
|
|
432
|
+
|
|
433
|
+
#### Inherited from
|
|
434
|
+
|
|
435
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`[iterator]`](LinearLinkedBase.md#iterator)
|
|
436
|
+
|
|
437
|
+
***
|
|
438
|
+
|
|
439
|
+
### addAfter()
|
|
440
|
+
|
|
441
|
+
```ts
|
|
442
|
+
addAfter(existingElementOrNode, newElementOrNode): boolean;
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:1141](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L1141)
|
|
446
|
+
|
|
447
|
+
Insert a new element/node after an existing one.
|
|
448
|
+
|
|
449
|
+
#### Parameters
|
|
450
|
+
|
|
451
|
+
##### existingElementOrNode
|
|
452
|
+
|
|
453
|
+
`E` \| [`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\>
|
|
454
|
+
|
|
455
|
+
Existing element or node.
|
|
456
|
+
|
|
457
|
+
##### newElementOrNode
|
|
458
|
+
|
|
459
|
+
`E` \| [`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\>
|
|
460
|
+
|
|
461
|
+
Element or node to insert.
|
|
462
|
+
|
|
463
|
+
#### Returns
|
|
464
|
+
|
|
465
|
+
`boolean`
|
|
466
|
+
|
|
467
|
+
True if inserted.
|
|
468
|
+
|
|
469
|
+
#### Remarks
|
|
470
|
+
|
|
471
|
+
Time O(N), Space O(1)
|
|
472
|
+
|
|
473
|
+
#### Overrides
|
|
474
|
+
|
|
475
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`addAfter`](LinearLinkedBase.md#addafter)
|
|
476
|
+
|
|
477
|
+
***
|
|
478
|
+
|
|
479
|
+
### addAt()
|
|
480
|
+
|
|
481
|
+
```ts
|
|
482
|
+
addAt(index, newElementOrNode): boolean;
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:898](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L898)
|
|
486
|
+
|
|
487
|
+
Insert a new element/node at an index, shifting following nodes.
|
|
488
|
+
|
|
489
|
+
#### Parameters
|
|
490
|
+
|
|
491
|
+
##### index
|
|
492
|
+
|
|
493
|
+
`number`
|
|
494
|
+
|
|
495
|
+
Zero-based index.
|
|
496
|
+
|
|
497
|
+
##### newElementOrNode
|
|
498
|
+
|
|
499
|
+
`E` \| [`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\>
|
|
500
|
+
|
|
501
|
+
Element or node to insert.
|
|
502
|
+
|
|
503
|
+
#### Returns
|
|
504
|
+
|
|
505
|
+
`boolean`
|
|
506
|
+
|
|
507
|
+
True if inserted.
|
|
508
|
+
|
|
509
|
+
*
|
|
510
|
+
|
|
511
|
+
#### Remarks
|
|
512
|
+
|
|
513
|
+
Time O(N), Space O(1)
|
|
514
|
+
|
|
515
|
+
#### Example
|
|
516
|
+
|
|
517
|
+
```ts
|
|
518
|
+
// Insert at index
|
|
519
|
+
const list = new SinglyLinkedList<number>([1, 3]);
|
|
520
|
+
list.addAt(1, 2);
|
|
521
|
+
console.log(list.toArray()); // [1, 2, 3];
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
#### Overrides
|
|
525
|
+
|
|
526
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`addAt`](LinearLinkedBase.md#addat)
|
|
527
|
+
|
|
528
|
+
***
|
|
529
|
+
|
|
530
|
+
### addBefore()
|
|
531
|
+
|
|
532
|
+
```ts
|
|
533
|
+
addBefore(existingElementOrNode, newElementOrNode): boolean;
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:1111](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L1111)
|
|
537
|
+
|
|
538
|
+
Insert a new element/node before an existing one.
|
|
539
|
+
|
|
540
|
+
#### Parameters
|
|
541
|
+
|
|
542
|
+
##### existingElementOrNode
|
|
543
|
+
|
|
544
|
+
`E` \| [`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\>
|
|
545
|
+
|
|
546
|
+
Existing element or node.
|
|
547
|
+
|
|
548
|
+
##### newElementOrNode
|
|
549
|
+
|
|
550
|
+
`E` \| [`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\>
|
|
551
|
+
|
|
552
|
+
Element or node to insert.
|
|
553
|
+
|
|
554
|
+
#### Returns
|
|
555
|
+
|
|
556
|
+
`boolean`
|
|
557
|
+
|
|
558
|
+
True if inserted.
|
|
559
|
+
|
|
560
|
+
#### Remarks
|
|
561
|
+
|
|
562
|
+
Time O(N), Space O(1)
|
|
563
|
+
|
|
564
|
+
#### Overrides
|
|
565
|
+
|
|
566
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`addBefore`](LinearLinkedBase.md#addbefore)
|
|
567
|
+
|
|
568
|
+
***
|
|
569
|
+
|
|
570
|
+
### at()
|
|
571
|
+
|
|
572
|
+
```ts
|
|
573
|
+
at(index): E | undefined;
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:666](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L666)
|
|
577
|
+
|
|
578
|
+
Get the element at a given index.
|
|
579
|
+
|
|
580
|
+
#### Parameters
|
|
581
|
+
|
|
582
|
+
##### index
|
|
583
|
+
|
|
584
|
+
`number`
|
|
585
|
+
|
|
586
|
+
Zero-based index.
|
|
587
|
+
|
|
588
|
+
#### Returns
|
|
589
|
+
|
|
590
|
+
`E` \| `undefined`
|
|
591
|
+
|
|
592
|
+
Element or undefined.
|
|
593
|
+
|
|
594
|
+
*
|
|
595
|
+
|
|
596
|
+
#### Remarks
|
|
597
|
+
|
|
598
|
+
Time O(N), Space O(1)
|
|
599
|
+
|
|
600
|
+
#### Example
|
|
601
|
+
|
|
602
|
+
```ts
|
|
603
|
+
// Access element by index
|
|
604
|
+
const list = new SinglyLinkedList<string>(['a', 'b', 'c', 'd']);
|
|
605
|
+
console.log(list.at(0)); // 'a';
|
|
606
|
+
console.log(list.at(2)); // 'c';
|
|
607
|
+
console.log(list.at(3)); // 'd';
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
#### Overrides
|
|
611
|
+
|
|
612
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`at`](LinearLinkedBase.md#at)
|
|
613
|
+
|
|
614
|
+
***
|
|
615
|
+
|
|
616
|
+
### clear()
|
|
617
|
+
|
|
618
|
+
```ts
|
|
619
|
+
clear(): void;
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:1015](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L1015)
|
|
623
|
+
|
|
624
|
+
Remove all nodes and reset length.
|
|
625
|
+
|
|
626
|
+
#### Returns
|
|
627
|
+
|
|
628
|
+
`void`
|
|
629
|
+
|
|
630
|
+
void
|
|
631
|
+
|
|
632
|
+
*
|
|
633
|
+
|
|
634
|
+
#### Remarks
|
|
635
|
+
|
|
636
|
+
Time O(N), Space O(1)
|
|
637
|
+
|
|
638
|
+
#### Example
|
|
639
|
+
|
|
640
|
+
```ts
|
|
641
|
+
// Remove all
|
|
642
|
+
const list = new SinglyLinkedList<number>([1, 2, 3]);
|
|
643
|
+
list.clear();
|
|
644
|
+
console.log(list.isEmpty()); // true;
|
|
645
|
+
```
|
|
646
|
+
|
|
647
|
+
#### Overrides
|
|
648
|
+
|
|
649
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`clear`](LinearLinkedBase.md#clear)
|
|
650
|
+
|
|
651
|
+
***
|
|
652
|
+
|
|
653
|
+
### clone()
|
|
654
|
+
|
|
655
|
+
```ts
|
|
656
|
+
clone(): this;
|
|
657
|
+
```
|
|
658
|
+
|
|
659
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:1315](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L1315)
|
|
660
|
+
|
|
661
|
+
Deep clone this list (values are copied by reference).
|
|
662
|
+
|
|
663
|
+
#### Returns
|
|
664
|
+
|
|
665
|
+
`this`
|
|
666
|
+
|
|
667
|
+
A new list with the same element sequence.
|
|
668
|
+
|
|
669
|
+
*
|
|
670
|
+
|
|
671
|
+
#### Remarks
|
|
672
|
+
|
|
673
|
+
Time O(N), Space O(N)
|
|
674
|
+
|
|
675
|
+
#### Example
|
|
676
|
+
|
|
677
|
+
```ts
|
|
678
|
+
// Deep copy
|
|
679
|
+
const list = new SinglyLinkedList<number>([1, 2, 3]);
|
|
680
|
+
const copy = list.clone();
|
|
681
|
+
copy.pop();
|
|
682
|
+
console.log(list.length); // 3;
|
|
683
|
+
console.log(copy.length); // 2;
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
#### Overrides
|
|
687
|
+
|
|
688
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`clone`](LinearLinkedBase.md#clone)
|
|
689
|
+
|
|
690
|
+
***
|
|
691
|
+
|
|
692
|
+
### concat()
|
|
693
|
+
|
|
694
|
+
```ts
|
|
695
|
+
concat(...items): this;
|
|
696
|
+
```
|
|
697
|
+
|
|
698
|
+
Defined in: [data-structures/base/linear-base.ts:473](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/linear-base.ts#L473)
|
|
699
|
+
|
|
700
|
+
Concatenate lists/elements preserving order.
|
|
701
|
+
|
|
702
|
+
#### Parameters
|
|
703
|
+
|
|
704
|
+
##### items
|
|
705
|
+
|
|
706
|
+
...(
|
|
707
|
+
\| `E`
|
|
708
|
+
\| [`LinearBase`](LinearBase.md)\<`E`, `R`, [`LinkedListNode`](LinkedListNode.md)\<`E`\>\>)[]
|
|
709
|
+
|
|
710
|
+
Elements or `LinearBase` instances.
|
|
711
|
+
|
|
712
|
+
#### Returns
|
|
713
|
+
|
|
714
|
+
`this`
|
|
715
|
+
|
|
716
|
+
New list with combined elements (`this` type).
|
|
717
|
+
|
|
718
|
+
#### Remarks
|
|
719
|
+
|
|
720
|
+
Time O(sum(length)), Space O(sum(length))
|
|
721
|
+
|
|
722
|
+
#### Inherited from
|
|
723
|
+
|
|
724
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`concat`](LinearLinkedBase.md#concat)
|
|
725
|
+
|
|
726
|
+
***
|
|
727
|
+
|
|
728
|
+
### countOccurrences()
|
|
729
|
+
|
|
730
|
+
```ts
|
|
731
|
+
countOccurrences(elementOrNode): number;
|
|
732
|
+
```
|
|
733
|
+
|
|
734
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:1217](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L1217)
|
|
735
|
+
|
|
736
|
+
Count how many nodes match a value/node/predicate.
|
|
737
|
+
|
|
738
|
+
#### Parameters
|
|
739
|
+
|
|
740
|
+
##### elementOrNode
|
|
741
|
+
|
|
742
|
+
\| `E`
|
|
743
|
+
\| [`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\>
|
|
744
|
+
\| ((`node`) => `boolean`)
|
|
745
|
+
|
|
746
|
+
Element, node, or node predicate to match.
|
|
747
|
+
|
|
748
|
+
#### Returns
|
|
749
|
+
|
|
750
|
+
`number`
|
|
751
|
+
|
|
752
|
+
Number of matches in the list.
|
|
753
|
+
|
|
754
|
+
#### Remarks
|
|
755
|
+
|
|
756
|
+
Time O(N), Space O(1)
|
|
757
|
+
|
|
758
|
+
***
|
|
759
|
+
|
|
760
|
+
### delete()
|
|
761
|
+
|
|
762
|
+
```ts
|
|
763
|
+
delete(elementOrNode?): boolean;
|
|
764
|
+
```
|
|
765
|
+
|
|
766
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:836](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L836)
|
|
767
|
+
|
|
768
|
+
Delete the first match by value/node.
|
|
769
|
+
|
|
770
|
+
#### Parameters
|
|
771
|
+
|
|
772
|
+
##### elementOrNode?
|
|
773
|
+
|
|
774
|
+
`E` \| [`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\>
|
|
775
|
+
|
|
776
|
+
Element or node to remove; if omitted/undefined, nothing happens.
|
|
777
|
+
|
|
778
|
+
#### Returns
|
|
779
|
+
|
|
780
|
+
`boolean`
|
|
781
|
+
|
|
782
|
+
True if removed.
|
|
783
|
+
|
|
784
|
+
*
|
|
785
|
+
|
|
786
|
+
#### Remarks
|
|
787
|
+
|
|
788
|
+
Time O(N), Space O(1)
|
|
789
|
+
|
|
790
|
+
#### Example
|
|
791
|
+
|
|
792
|
+
```ts
|
|
793
|
+
// Remove first occurrence
|
|
794
|
+
const list = new SinglyLinkedList<number>([1, 2, 3, 2]);
|
|
795
|
+
list.delete(2);
|
|
796
|
+
console.log(list.toArray()); // [1, 3, 2];
|
|
797
|
+
```
|
|
798
|
+
|
|
799
|
+
#### Overrides
|
|
800
|
+
|
|
801
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`delete`](LinearLinkedBase.md#delete)
|
|
802
|
+
|
|
803
|
+
***
|
|
804
|
+
|
|
805
|
+
### deleteAt()
|
|
806
|
+
|
|
807
|
+
```ts
|
|
808
|
+
deleteAt(index): E | undefined;
|
|
809
|
+
```
|
|
810
|
+
|
|
811
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:780](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L780)
|
|
812
|
+
|
|
813
|
+
Delete the element at an index.
|
|
814
|
+
|
|
815
|
+
#### Parameters
|
|
816
|
+
|
|
817
|
+
##### index
|
|
818
|
+
|
|
819
|
+
`number`
|
|
820
|
+
|
|
821
|
+
Zero-based index.
|
|
822
|
+
|
|
823
|
+
#### Returns
|
|
824
|
+
|
|
825
|
+
`E` \| `undefined`
|
|
826
|
+
|
|
827
|
+
Removed element or undefined.
|
|
828
|
+
|
|
829
|
+
*
|
|
830
|
+
|
|
831
|
+
#### Remarks
|
|
832
|
+
|
|
833
|
+
Time O(N), Space O(1)
|
|
834
|
+
|
|
835
|
+
#### Example
|
|
836
|
+
|
|
837
|
+
```ts
|
|
838
|
+
// Remove by index
|
|
839
|
+
const list = new SinglyLinkedList<string>(['a', 'b', 'c']);
|
|
840
|
+
list.deleteAt(1);
|
|
841
|
+
console.log(list.toArray()); // ['a', 'c'];
|
|
842
|
+
```
|
|
843
|
+
|
|
844
|
+
#### Overrides
|
|
845
|
+
|
|
846
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`deleteAt`](LinearLinkedBase.md#deleteat)
|
|
847
|
+
|
|
848
|
+
***
|
|
849
|
+
|
|
850
|
+
### deleteWhere()
|
|
851
|
+
|
|
852
|
+
```ts
|
|
853
|
+
deleteWhere(predicate): boolean;
|
|
854
|
+
```
|
|
855
|
+
|
|
856
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:1247](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L1247)
|
|
857
|
+
|
|
858
|
+
Delete the first node whose value matches a predicate.
|
|
859
|
+
|
|
860
|
+
#### Parameters
|
|
861
|
+
|
|
862
|
+
##### predicate
|
|
863
|
+
|
|
864
|
+
(`value`, `index`, `list`) => `boolean`
|
|
865
|
+
|
|
866
|
+
Predicate (value, index, list) → boolean to decide deletion.
|
|
867
|
+
|
|
868
|
+
#### Returns
|
|
869
|
+
|
|
870
|
+
`boolean`
|
|
871
|
+
|
|
872
|
+
True if a node was removed.
|
|
873
|
+
|
|
874
|
+
#### Remarks
|
|
875
|
+
|
|
876
|
+
Time O(N), Space O(1)
|
|
877
|
+
|
|
878
|
+
***
|
|
879
|
+
|
|
880
|
+
### every()
|
|
881
|
+
|
|
882
|
+
```ts
|
|
883
|
+
every(predicate, thisArg?): boolean;
|
|
884
|
+
```
|
|
885
|
+
|
|
886
|
+
Defined in: [data-structures/base/iterable-element-base.ts:87](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L87)
|
|
887
|
+
|
|
888
|
+
Tests whether all elements satisfy the predicate.
|
|
889
|
+
|
|
890
|
+
#### Parameters
|
|
891
|
+
|
|
892
|
+
##### predicate
|
|
893
|
+
|
|
894
|
+
`ElementCallback`\<`E`, `R`, `boolean`\>
|
|
895
|
+
|
|
896
|
+
Function invoked for each element with signature `(value, index, self)`.
|
|
897
|
+
|
|
898
|
+
##### thisArg?
|
|
899
|
+
|
|
900
|
+
`unknown`
|
|
901
|
+
|
|
902
|
+
Optional `this` binding for the predicate.
|
|
903
|
+
|
|
904
|
+
#### Returns
|
|
905
|
+
|
|
906
|
+
`boolean`
|
|
907
|
+
|
|
908
|
+
`true` if every element passes; otherwise `false`.
|
|
909
|
+
|
|
910
|
+
#### Remarks
|
|
911
|
+
|
|
912
|
+
Time O(n) in the worst case; may exit early when the first failure is found. Space O(1).
|
|
913
|
+
|
|
914
|
+
#### Inherited from
|
|
915
|
+
|
|
916
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`every`](LinearLinkedBase.md#every)
|
|
917
|
+
|
|
918
|
+
***
|
|
919
|
+
|
|
920
|
+
### fill()
|
|
921
|
+
|
|
922
|
+
```ts
|
|
923
|
+
fill(
|
|
924
|
+
value,
|
|
925
|
+
start?,
|
|
926
|
+
end?): this;
|
|
927
|
+
```
|
|
928
|
+
|
|
929
|
+
Defined in: [data-structures/base/linear-base.ts:292](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/linear-base.ts#L292)
|
|
930
|
+
|
|
931
|
+
Fill a range with a value.
|
|
932
|
+
|
|
933
|
+
#### Parameters
|
|
934
|
+
|
|
935
|
+
##### value
|
|
936
|
+
|
|
937
|
+
`E`
|
|
938
|
+
|
|
939
|
+
Value to set.
|
|
940
|
+
|
|
941
|
+
##### start?
|
|
942
|
+
|
|
943
|
+
`number` = `0`
|
|
944
|
+
|
|
945
|
+
Inclusive start.
|
|
946
|
+
|
|
947
|
+
##### end?
|
|
948
|
+
|
|
949
|
+
`number` = `...`
|
|
950
|
+
|
|
951
|
+
Exclusive end.
|
|
952
|
+
|
|
953
|
+
#### Returns
|
|
954
|
+
|
|
955
|
+
`this`
|
|
956
|
+
|
|
957
|
+
This list.
|
|
958
|
+
|
|
959
|
+
#### Remarks
|
|
960
|
+
|
|
961
|
+
Time O(n), Space O(1)
|
|
962
|
+
|
|
963
|
+
#### Inherited from
|
|
964
|
+
|
|
965
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`fill`](LinearLinkedBase.md#fill)
|
|
966
|
+
|
|
967
|
+
***
|
|
968
|
+
|
|
969
|
+
### filter()
|
|
970
|
+
|
|
971
|
+
```ts
|
|
972
|
+
filter(callback, thisArg?): this;
|
|
973
|
+
```
|
|
974
|
+
|
|
975
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:1379](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L1379)
|
|
976
|
+
|
|
977
|
+
Filter values into a new list of the same class.
|
|
978
|
+
|
|
979
|
+
#### Parameters
|
|
980
|
+
|
|
981
|
+
##### callback
|
|
982
|
+
|
|
983
|
+
`ElementCallback`\<`E`, `R`, `boolean`\>
|
|
984
|
+
|
|
985
|
+
Predicate (value, index, list) → boolean to keep value.
|
|
986
|
+
|
|
987
|
+
##### thisArg?
|
|
988
|
+
|
|
989
|
+
`unknown`
|
|
990
|
+
|
|
991
|
+
Value for `this` inside the callback.
|
|
992
|
+
|
|
993
|
+
#### Returns
|
|
994
|
+
|
|
995
|
+
`this`
|
|
996
|
+
|
|
997
|
+
A new list with kept values.
|
|
998
|
+
|
|
999
|
+
*
|
|
1000
|
+
|
|
1001
|
+
#### Remarks
|
|
1002
|
+
|
|
1003
|
+
Time O(N), Space O(N)
|
|
1004
|
+
|
|
1005
|
+
#### Example
|
|
1006
|
+
|
|
1007
|
+
```ts
|
|
1008
|
+
// SinglyLinkedList filter and map operations
|
|
1009
|
+
const list = new SinglyLinkedList<number>([1, 2, 3, 4, 5]);
|
|
1010
|
+
|
|
1011
|
+
// Filter even numbers
|
|
1012
|
+
const filtered = list.filter(value => value % 2 === 0);
|
|
1013
|
+
console.log(filtered.length); // 2;
|
|
1014
|
+
|
|
1015
|
+
// Map to double values
|
|
1016
|
+
const doubled = list.map(value => value * 2);
|
|
1017
|
+
console.log(doubled.length); // 5;
|
|
1018
|
+
|
|
1019
|
+
// Use reduce to sum
|
|
1020
|
+
const sum = list.reduce((acc, value) => acc + value, 0);
|
|
1021
|
+
console.log(sum); // 15;
|
|
1022
|
+
```
|
|
1023
|
+
|
|
1024
|
+
#### Overrides
|
|
1025
|
+
|
|
1026
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`filter`](LinearLinkedBase.md#filter)
|
|
1027
|
+
|
|
1028
|
+
***
|
|
1029
|
+
|
|
1030
|
+
### find()
|
|
1031
|
+
|
|
1032
|
+
#### Call Signature
|
|
1033
|
+
|
|
1034
|
+
```ts
|
|
1035
|
+
find<S>(predicate, thisArg?): S | undefined;
|
|
1036
|
+
```
|
|
1037
|
+
|
|
1038
|
+
Defined in: [data-structures/base/iterable-element-base.ts:163](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L163)
|
|
1039
|
+
|
|
1040
|
+
Finds the first element that satisfies the predicate and returns it.
|
|
1041
|
+
|
|
1042
|
+
Finds the first element of type `S` (a subtype of `E`) that satisfies the predicate and returns it.
|
|
1043
|
+
|
|
1044
|
+
##### Type Parameters
|
|
1045
|
+
|
|
1046
|
+
###### S
|
|
1047
|
+
|
|
1048
|
+
`S`
|
|
1049
|
+
|
|
1050
|
+
##### Parameters
|
|
1051
|
+
|
|
1052
|
+
###### predicate
|
|
1053
|
+
|
|
1054
|
+
`ElementCallback`\<`E`, `R`, `S`\>
|
|
1055
|
+
|
|
1056
|
+
Type-guard predicate: `(value, index, self) => value is S`.
|
|
1057
|
+
|
|
1058
|
+
###### thisArg?
|
|
1059
|
+
|
|
1060
|
+
`unknown`
|
|
1061
|
+
|
|
1062
|
+
Optional `this` binding for the predicate.
|
|
1063
|
+
|
|
1064
|
+
##### Returns
|
|
1065
|
+
|
|
1066
|
+
`S` \| `undefined`
|
|
1067
|
+
|
|
1068
|
+
The matched element typed as `S`, or `undefined` if not found.
|
|
1069
|
+
|
|
1070
|
+
##### Remarks
|
|
1071
|
+
|
|
1072
|
+
Time O(n) in the worst case; may exit early on the first match. Space O(1).
|
|
1073
|
+
|
|
1074
|
+
##### Inherited from
|
|
1075
|
+
|
|
1076
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`find`](LinearLinkedBase.md#find)
|
|
1077
|
+
|
|
1078
|
+
#### Call Signature
|
|
1079
|
+
|
|
1080
|
+
```ts
|
|
1081
|
+
find(predicate, thisArg?): E | undefined;
|
|
1082
|
+
```
|
|
1083
|
+
|
|
1084
|
+
Defined in: [data-structures/base/iterable-element-base.ts:164](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L164)
|
|
1085
|
+
|
|
1086
|
+
Finds the first element that satisfies the predicate and returns it.
|
|
1087
|
+
|
|
1088
|
+
Finds the first element of type `S` (a subtype of `E`) that satisfies the predicate and returns it.
|
|
1089
|
+
|
|
1090
|
+
##### Parameters
|
|
1091
|
+
|
|
1092
|
+
###### predicate
|
|
1093
|
+
|
|
1094
|
+
`ElementCallback`\<`E`, `R`, `unknown`\>
|
|
1095
|
+
|
|
1096
|
+
Type-guard predicate: `(value, index, self) => value is S`.
|
|
1097
|
+
|
|
1098
|
+
###### thisArg?
|
|
1099
|
+
|
|
1100
|
+
`unknown`
|
|
1101
|
+
|
|
1102
|
+
Optional `this` binding for the predicate.
|
|
1103
|
+
|
|
1104
|
+
##### Returns
|
|
1105
|
+
|
|
1106
|
+
`E` \| `undefined`
|
|
1107
|
+
|
|
1108
|
+
The matched element typed as `S`, or `undefined` if not found.
|
|
1109
|
+
|
|
1110
|
+
##### Remarks
|
|
1111
|
+
|
|
1112
|
+
Time O(n) in the worst case; may exit early on the first match. Space O(1).
|
|
1113
|
+
|
|
1114
|
+
##### Inherited from
|
|
1115
|
+
|
|
1116
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`find`](LinearLinkedBase.md#find)
|
|
1117
|
+
|
|
1118
|
+
***
|
|
1119
|
+
|
|
1120
|
+
### findIndex()
|
|
1121
|
+
|
|
1122
|
+
```ts
|
|
1123
|
+
findIndex(predicate, thisArg?): number;
|
|
1124
|
+
```
|
|
1125
|
+
|
|
1126
|
+
Defined in: [data-structures/base/linear-base.ts:151](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/linear-base.ts#L151)
|
|
1127
|
+
|
|
1128
|
+
Find the first index matching a predicate.
|
|
1129
|
+
|
|
1130
|
+
#### Parameters
|
|
1131
|
+
|
|
1132
|
+
##### predicate
|
|
1133
|
+
|
|
1134
|
+
`ElementCallback`\<`E`, `R`, `boolean`\>
|
|
1135
|
+
|
|
1136
|
+
`(element, index, self) => boolean`.
|
|
1137
|
+
|
|
1138
|
+
##### thisArg?
|
|
1139
|
+
|
|
1140
|
+
`unknown`
|
|
1141
|
+
|
|
1142
|
+
Optional `this` for callback.
|
|
1143
|
+
|
|
1144
|
+
#### Returns
|
|
1145
|
+
|
|
1146
|
+
`number`
|
|
1147
|
+
|
|
1148
|
+
Index or `-1`.
|
|
1149
|
+
|
|
1150
|
+
#### Remarks
|
|
1151
|
+
|
|
1152
|
+
Time O(n), Space O(1)
|
|
1153
|
+
|
|
1154
|
+
#### Inherited from
|
|
1155
|
+
|
|
1156
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`findIndex`](LinearLinkedBase.md#findindex)
|
|
1157
|
+
|
|
1158
|
+
***
|
|
1159
|
+
|
|
1160
|
+
### forEach()
|
|
1161
|
+
|
|
1162
|
+
```ts
|
|
1163
|
+
forEach(callbackfn, thisArg?): void;
|
|
1164
|
+
```
|
|
1165
|
+
|
|
1166
|
+
Defined in: [data-structures/base/iterable-element-base.ts:133](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L133)
|
|
1167
|
+
|
|
1168
|
+
Invokes a callback for each element in iteration order.
|
|
1169
|
+
|
|
1170
|
+
#### Parameters
|
|
1171
|
+
|
|
1172
|
+
##### callbackfn
|
|
1173
|
+
|
|
1174
|
+
`ElementCallback`\<`E`, `R`, `void`\>
|
|
1175
|
+
|
|
1176
|
+
Function invoked per element with signature `(value, index, self)`.
|
|
1177
|
+
|
|
1178
|
+
##### thisArg?
|
|
1179
|
+
|
|
1180
|
+
`unknown`
|
|
1181
|
+
|
|
1182
|
+
Optional `this` binding for the callback.
|
|
1183
|
+
|
|
1184
|
+
#### Returns
|
|
1185
|
+
|
|
1186
|
+
`void`
|
|
1187
|
+
|
|
1188
|
+
`void`.
|
|
1189
|
+
|
|
1190
|
+
#### Remarks
|
|
1191
|
+
|
|
1192
|
+
Time O(n), Space O(1).
|
|
1193
|
+
|
|
1194
|
+
#### Inherited from
|
|
1195
|
+
|
|
1196
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`forEach`](LinearLinkedBase.md#foreach)
|
|
1197
|
+
|
|
1198
|
+
***
|
|
1199
|
+
|
|
1200
|
+
### getNode()
|
|
1201
|
+
|
|
1202
|
+
```ts
|
|
1203
|
+
getNode(elementNodeOrPredicate?): SinglyLinkedListNode<E> | undefined;
|
|
1204
|
+
```
|
|
1205
|
+
|
|
1206
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:1089](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L1089)
|
|
1207
|
+
|
|
1208
|
+
Find a node by value, reference, or predicate.
|
|
1209
|
+
|
|
1210
|
+
#### Parameters
|
|
1211
|
+
|
|
1212
|
+
##### elementNodeOrPredicate?
|
|
1213
|
+
|
|
1214
|
+
\| `E`
|
|
1215
|
+
\| [`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\>
|
|
1216
|
+
\| ((`node`) => `boolean`)
|
|
1217
|
+
|
|
1218
|
+
Element, node, or node predicate to match.
|
|
1219
|
+
|
|
1220
|
+
#### Returns
|
|
1221
|
+
|
|
1222
|
+
[`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\> \| `undefined`
|
|
1223
|
+
|
|
1224
|
+
Matching node or undefined.
|
|
1225
|
+
|
|
1226
|
+
#### Remarks
|
|
1227
|
+
|
|
1228
|
+
Time O(N), Space O(1)
|
|
1229
|
+
|
|
1230
|
+
***
|
|
1231
|
+
|
|
1232
|
+
### getNodeAt()
|
|
1233
|
+
|
|
1234
|
+
```ts
|
|
1235
|
+
getNodeAt(index): SinglyLinkedListNode<E> | undefined;
|
|
1236
|
+
```
|
|
1237
|
+
|
|
1238
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:729](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L729)
|
|
1239
|
+
|
|
1240
|
+
Get the node reference at a given index.
|
|
1241
|
+
|
|
1242
|
+
#### Parameters
|
|
1243
|
+
|
|
1244
|
+
##### index
|
|
1245
|
+
|
|
1246
|
+
`number`
|
|
1247
|
+
|
|
1248
|
+
Zero-based index.
|
|
1249
|
+
|
|
1250
|
+
#### Returns
|
|
1251
|
+
|
|
1252
|
+
[`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\> \| `undefined`
|
|
1253
|
+
|
|
1254
|
+
Node or undefined.
|
|
1255
|
+
|
|
1256
|
+
*
|
|
1257
|
+
|
|
1258
|
+
#### Remarks
|
|
1259
|
+
|
|
1260
|
+
Time O(N), Space O(1)
|
|
1261
|
+
|
|
1262
|
+
#### Example
|
|
1263
|
+
|
|
1264
|
+
```ts
|
|
1265
|
+
// Get node at index
|
|
1266
|
+
const list = new SinglyLinkedList<string>(['a', 'b', 'c']);
|
|
1267
|
+
console.log(list.getNodeAt(1)?.value); // 'b';
|
|
1268
|
+
```
|
|
1269
|
+
|
|
1270
|
+
#### Overrides
|
|
1271
|
+
|
|
1272
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`getNodeAt`](LinearLinkedBase.md#getnodeat)
|
|
1273
|
+
|
|
1274
|
+
***
|
|
1275
|
+
|
|
1276
|
+
### has()
|
|
1277
|
+
|
|
1278
|
+
```ts
|
|
1279
|
+
has(element): boolean;
|
|
1280
|
+
```
|
|
1281
|
+
|
|
1282
|
+
Defined in: [data-structures/base/iterable-element-base.ts:189](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L189)
|
|
1283
|
+
|
|
1284
|
+
Checks whether a strictly-equal element exists in the structure.
|
|
1285
|
+
|
|
1286
|
+
#### Parameters
|
|
1287
|
+
|
|
1288
|
+
##### element
|
|
1289
|
+
|
|
1290
|
+
`E`
|
|
1291
|
+
|
|
1292
|
+
The element to test with `===` equality.
|
|
1293
|
+
|
|
1294
|
+
#### Returns
|
|
1295
|
+
|
|
1296
|
+
`boolean`
|
|
1297
|
+
|
|
1298
|
+
`true` if an equal element is found; otherwise `false`.
|
|
1299
|
+
|
|
1300
|
+
#### Remarks
|
|
1301
|
+
|
|
1302
|
+
Time O(n) in the worst case. Space O(1).
|
|
1303
|
+
|
|
1304
|
+
#### Inherited from
|
|
1305
|
+
|
|
1306
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`has`](LinearLinkedBase.md#has)
|
|
1307
|
+
|
|
1308
|
+
***
|
|
1309
|
+
|
|
1310
|
+
### indexOf()
|
|
1311
|
+
|
|
1312
|
+
```ts
|
|
1313
|
+
indexOf(searchElement, fromIndex?): number;
|
|
1314
|
+
```
|
|
1315
|
+
|
|
1316
|
+
Defined in: [data-structures/base/linear-base.ts:422](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/linear-base.ts#L422)
|
|
1317
|
+
|
|
1318
|
+
Linked-list optimized `indexOf` (forwards scan).
|
|
1319
|
+
|
|
1320
|
+
#### Parameters
|
|
1321
|
+
|
|
1322
|
+
##### searchElement
|
|
1323
|
+
|
|
1324
|
+
`E`
|
|
1325
|
+
|
|
1326
|
+
Value to match.
|
|
1327
|
+
|
|
1328
|
+
##### fromIndex?
|
|
1329
|
+
|
|
1330
|
+
`number` = `0`
|
|
1331
|
+
|
|
1332
|
+
Start position.
|
|
1333
|
+
|
|
1334
|
+
#### Returns
|
|
1335
|
+
|
|
1336
|
+
`number`
|
|
1337
|
+
|
|
1338
|
+
Index or `-1`.
|
|
1339
|
+
|
|
1340
|
+
#### Remarks
|
|
1341
|
+
|
|
1342
|
+
Time O(n), Space O(1)
|
|
1343
|
+
|
|
1344
|
+
#### Inherited from
|
|
1345
|
+
|
|
1346
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`indexOf`](LinearLinkedBase.md#indexof)
|
|
1347
|
+
|
|
1348
|
+
***
|
|
1349
|
+
|
|
1350
|
+
### isEmpty()
|
|
1351
|
+
|
|
1352
|
+
```ts
|
|
1353
|
+
isEmpty(): boolean;
|
|
1354
|
+
```
|
|
1355
|
+
|
|
1356
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:967](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L967)
|
|
1357
|
+
|
|
1358
|
+
Check whether the list is empty.
|
|
1359
|
+
|
|
1360
|
+
#### Returns
|
|
1361
|
+
|
|
1362
|
+
`boolean`
|
|
1363
|
+
|
|
1364
|
+
True if length is 0.
|
|
1365
|
+
|
|
1366
|
+
*
|
|
1367
|
+
|
|
1368
|
+
#### Remarks
|
|
1369
|
+
|
|
1370
|
+
Time O(1), Space O(1)
|
|
1371
|
+
|
|
1372
|
+
#### Example
|
|
1373
|
+
|
|
1374
|
+
```ts
|
|
1375
|
+
// Check empty
|
|
1376
|
+
console.log(new SinglyLinkedList().isEmpty()); // true;
|
|
1377
|
+
```
|
|
1378
|
+
|
|
1379
|
+
#### Overrides
|
|
1380
|
+
|
|
1381
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`isEmpty`](LinearLinkedBase.md#isempty)
|
|
1382
|
+
|
|
1383
|
+
***
|
|
1384
|
+
|
|
1385
|
+
### isNode()
|
|
1386
|
+
|
|
1387
|
+
```ts
|
|
1388
|
+
isNode(elementNodeOrPredicate): elementNodeOrPredicate is SinglyLinkedListNode<E>;
|
|
1389
|
+
```
|
|
1390
|
+
|
|
1391
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:680](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L680)
|
|
1392
|
+
|
|
1393
|
+
Type guard: check whether the input is a SinglyLinkedListNode.
|
|
1394
|
+
|
|
1395
|
+
#### Parameters
|
|
1396
|
+
|
|
1397
|
+
##### elementNodeOrPredicate
|
|
1398
|
+
|
|
1399
|
+
\| `E`
|
|
1400
|
+
\| [`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\>
|
|
1401
|
+
\| ((`node`) => `boolean`)
|
|
1402
|
+
|
|
1403
|
+
Element, node, or predicate.
|
|
1404
|
+
|
|
1405
|
+
#### Returns
|
|
1406
|
+
|
|
1407
|
+
`elementNodeOrPredicate is SinglyLinkedListNode<E>`
|
|
1408
|
+
|
|
1409
|
+
True if the value is a SinglyLinkedListNode.
|
|
1410
|
+
|
|
1411
|
+
#### Remarks
|
|
1412
|
+
|
|
1413
|
+
Time O(1), Space O(1)
|
|
1414
|
+
|
|
1415
|
+
***
|
|
1416
|
+
|
|
1417
|
+
### join()
|
|
1418
|
+
|
|
1419
|
+
```ts
|
|
1420
|
+
join(separator?): string;
|
|
1421
|
+
```
|
|
1422
|
+
|
|
1423
|
+
Defined in: [data-structures/base/linear-base.ts:228](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/linear-base.ts#L228)
|
|
1424
|
+
|
|
1425
|
+
Join all elements into a string.
|
|
1426
|
+
|
|
1427
|
+
#### Parameters
|
|
1428
|
+
|
|
1429
|
+
##### separator?
|
|
1430
|
+
|
|
1431
|
+
`string` = `','`
|
|
1432
|
+
|
|
1433
|
+
Separator string.
|
|
1434
|
+
|
|
1435
|
+
#### Returns
|
|
1436
|
+
|
|
1437
|
+
`string`
|
|
1438
|
+
|
|
1439
|
+
Concatenated string.
|
|
1440
|
+
|
|
1441
|
+
#### Remarks
|
|
1442
|
+
|
|
1443
|
+
Time O(n), Space O(n)
|
|
1444
|
+
|
|
1445
|
+
#### Inherited from
|
|
1446
|
+
|
|
1447
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`join`](LinearLinkedBase.md#join)
|
|
1448
|
+
|
|
1449
|
+
***
|
|
1450
|
+
|
|
1451
|
+
### lastIndexOf()
|
|
1452
|
+
|
|
1453
|
+
```ts
|
|
1454
|
+
lastIndexOf(searchElement, fromIndex?): number;
|
|
1455
|
+
```
|
|
1456
|
+
|
|
1457
|
+
Defined in: [data-structures/base/linear-base.ts:448](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/linear-base.ts#L448)
|
|
1458
|
+
|
|
1459
|
+
Linked-list optimized `lastIndexOf` (reverse scan).
|
|
1460
|
+
|
|
1461
|
+
#### Parameters
|
|
1462
|
+
|
|
1463
|
+
##### searchElement
|
|
1464
|
+
|
|
1465
|
+
`E`
|
|
1466
|
+
|
|
1467
|
+
Value to match.
|
|
1468
|
+
|
|
1469
|
+
##### fromIndex?
|
|
1470
|
+
|
|
1471
|
+
`number` = `...`
|
|
1472
|
+
|
|
1473
|
+
Start position.
|
|
1474
|
+
|
|
1475
|
+
#### Returns
|
|
1476
|
+
|
|
1477
|
+
`number`
|
|
1478
|
+
|
|
1479
|
+
Index or `-1`.
|
|
1480
|
+
|
|
1481
|
+
#### Remarks
|
|
1482
|
+
|
|
1483
|
+
Time O(n), Space O(1)
|
|
1484
|
+
|
|
1485
|
+
#### Inherited from
|
|
1486
|
+
|
|
1487
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`lastIndexOf`](LinearLinkedBase.md#lastindexof)
|
|
1488
|
+
|
|
1489
|
+
***
|
|
1490
|
+
|
|
1491
|
+
### map()
|
|
1492
|
+
|
|
1493
|
+
```ts
|
|
1494
|
+
map<EM, RM>(
|
|
1495
|
+
callback,
|
|
1496
|
+
options?,
|
|
1497
|
+
thisArg?): SinglyLinkedList<EM, RM>;
|
|
1498
|
+
```
|
|
1499
|
+
|
|
1500
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:1455](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L1455)
|
|
1501
|
+
|
|
1502
|
+
Map values into a new list (possibly different element type).
|
|
1503
|
+
|
|
1504
|
+
#### Type Parameters
|
|
1505
|
+
|
|
1506
|
+
##### EM
|
|
1507
|
+
|
|
1508
|
+
`EM`
|
|
1509
|
+
|
|
1510
|
+
##### RM
|
|
1511
|
+
|
|
1512
|
+
`RM` = `any`
|
|
1513
|
+
|
|
1514
|
+
#### Parameters
|
|
1515
|
+
|
|
1516
|
+
##### callback
|
|
1517
|
+
|
|
1518
|
+
`ElementCallback`\<`E`, `R`, `EM`\>
|
|
1519
|
+
|
|
1520
|
+
Mapping function (value, index, list) → newElement.
|
|
1521
|
+
|
|
1522
|
+
##### options?
|
|
1523
|
+
|
|
1524
|
+
`SinglyLinkedListOptions`\<`EM`, `RM`\>
|
|
1525
|
+
|
|
1526
|
+
Options for the output list (e.g., maxLen, toElementFn).
|
|
1527
|
+
|
|
1528
|
+
##### thisArg?
|
|
1529
|
+
|
|
1530
|
+
`unknown`
|
|
1531
|
+
|
|
1532
|
+
Value for `this` inside the callback.
|
|
1533
|
+
|
|
1534
|
+
#### Returns
|
|
1535
|
+
|
|
1536
|
+
`SinglyLinkedList`\<`EM`, `RM`\>
|
|
1537
|
+
|
|
1538
|
+
A new SinglyLinkedList with mapped values.
|
|
1539
|
+
|
|
1540
|
+
*
|
|
1541
|
+
|
|
1542
|
+
#### Remarks
|
|
1543
|
+
|
|
1544
|
+
Time O(N), Space O(N)
|
|
1545
|
+
|
|
1546
|
+
#### Example
|
|
1547
|
+
|
|
1548
|
+
```ts
|
|
1549
|
+
// Transform elements
|
|
1550
|
+
const list = new SinglyLinkedList<number>([1, 2, 3]);
|
|
1551
|
+
const doubled = list.map(n => n * 2);
|
|
1552
|
+
console.log([...doubled]); // [2, 4, 6];
|
|
1553
|
+
```
|
|
1554
|
+
|
|
1555
|
+
#### Overrides
|
|
1556
|
+
|
|
1557
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`map`](LinearLinkedBase.md#map)
|
|
1558
|
+
|
|
1559
|
+
***
|
|
1560
|
+
|
|
1561
|
+
### mapSame()
|
|
1562
|
+
|
|
1563
|
+
```ts
|
|
1564
|
+
mapSame(callback, thisArg?): this;
|
|
1565
|
+
```
|
|
1566
|
+
|
|
1567
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:1394](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L1394)
|
|
1568
|
+
|
|
1569
|
+
Map values into a new list of the same class.
|
|
1570
|
+
|
|
1571
|
+
#### Parameters
|
|
1572
|
+
|
|
1573
|
+
##### callback
|
|
1574
|
+
|
|
1575
|
+
`ElementCallback`\<`E`, `R`, `E`\>
|
|
1576
|
+
|
|
1577
|
+
Mapping function (value, index, list) → newValue.
|
|
1578
|
+
|
|
1579
|
+
##### thisArg?
|
|
1580
|
+
|
|
1581
|
+
`unknown`
|
|
1582
|
+
|
|
1583
|
+
Value for `this` inside the callback.
|
|
1584
|
+
|
|
1585
|
+
#### Returns
|
|
1586
|
+
|
|
1587
|
+
`this`
|
|
1588
|
+
|
|
1589
|
+
A new list with mapped values.
|
|
1590
|
+
|
|
1591
|
+
#### Remarks
|
|
1592
|
+
|
|
1593
|
+
Time O(N), Space O(N)
|
|
1594
|
+
|
|
1595
|
+
#### Overrides
|
|
1596
|
+
|
|
1597
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`mapSame`](LinearLinkedBase.md#mapsame)
|
|
1598
|
+
|
|
1599
|
+
***
|
|
1600
|
+
|
|
1601
|
+
### pop()
|
|
1602
|
+
|
|
1603
|
+
```ts
|
|
1604
|
+
pop(): E | undefined;
|
|
1605
|
+
```
|
|
1606
|
+
|
|
1607
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:420](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L420)
|
|
1608
|
+
|
|
1609
|
+
Remove and return the tail element.
|
|
1610
|
+
|
|
1611
|
+
#### Returns
|
|
1612
|
+
|
|
1613
|
+
`E` \| `undefined`
|
|
1614
|
+
|
|
1615
|
+
Removed element or undefined.
|
|
1616
|
+
|
|
1617
|
+
*
|
|
1618
|
+
|
|
1619
|
+
#### Remarks
|
|
1620
|
+
|
|
1621
|
+
Time O(N), Space O(1)
|
|
1622
|
+
|
|
1623
|
+
#### Example
|
|
1624
|
+
|
|
1625
|
+
```ts
|
|
1626
|
+
// SinglyLinkedList pop and shift operations
|
|
1627
|
+
const list = new SinglyLinkedList<number>([10, 20, 30, 40, 50]);
|
|
1628
|
+
|
|
1629
|
+
// Pop removes from the end
|
|
1630
|
+
const last = list.pop();
|
|
1631
|
+
console.log(last); // 50;
|
|
1632
|
+
|
|
1633
|
+
// Shift removes from the beginning
|
|
1634
|
+
const first = list.shift();
|
|
1635
|
+
console.log(first); // 10;
|
|
1636
|
+
|
|
1637
|
+
// Verify remaining elements
|
|
1638
|
+
console.log([...list]); // [20, 30, 40];
|
|
1639
|
+
console.log(list.length); // 3;
|
|
1640
|
+
```
|
|
1641
|
+
|
|
1642
|
+
***
|
|
1643
|
+
|
|
1644
|
+
### print()
|
|
1645
|
+
|
|
1646
|
+
```ts
|
|
1647
|
+
print(): void;
|
|
1648
|
+
```
|
|
1649
|
+
|
|
1650
|
+
Defined in: [data-structures/base/iterable-element-base.ts:269](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L269)
|
|
1651
|
+
|
|
1652
|
+
Prints `toVisual()` to the console. Intended for quick debugging.
|
|
1653
|
+
|
|
1654
|
+
#### Returns
|
|
1655
|
+
|
|
1656
|
+
`void`
|
|
1657
|
+
|
|
1658
|
+
`void`.
|
|
1659
|
+
|
|
1660
|
+
#### Remarks
|
|
1661
|
+
|
|
1662
|
+
Time O(n) due to materialization, Space O(n) for the intermediate representation.
|
|
1663
|
+
|
|
1664
|
+
#### Inherited from
|
|
1665
|
+
|
|
1666
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`print`](LinearLinkedBase.md#print)
|
|
1667
|
+
|
|
1668
|
+
***
|
|
1669
|
+
|
|
1670
|
+
### push()
|
|
1671
|
+
|
|
1672
|
+
```ts
|
|
1673
|
+
push(elementOrNode): boolean;
|
|
1674
|
+
```
|
|
1675
|
+
|
|
1676
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:351](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L351)
|
|
1677
|
+
|
|
1678
|
+
Append an element/node to the tail.
|
|
1679
|
+
|
|
1680
|
+
#### Parameters
|
|
1681
|
+
|
|
1682
|
+
##### elementOrNode
|
|
1683
|
+
|
|
1684
|
+
`E` \| [`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\>
|
|
1685
|
+
|
|
1686
|
+
Element or node to append.
|
|
1687
|
+
|
|
1688
|
+
#### Returns
|
|
1689
|
+
|
|
1690
|
+
`boolean`
|
|
1691
|
+
|
|
1692
|
+
True when appended.
|
|
1693
|
+
|
|
1694
|
+
*
|
|
1695
|
+
|
|
1696
|
+
#### Remarks
|
|
1697
|
+
|
|
1698
|
+
Time O(1), Space O(1)
|
|
1699
|
+
|
|
1700
|
+
#### Example
|
|
1701
|
+
|
|
1702
|
+
```ts
|
|
1703
|
+
// basic SinglyLinkedList creation and push operation
|
|
1704
|
+
// Create a simple SinglyLinkedList with initial values
|
|
1705
|
+
const list = new SinglyLinkedList([1, 2, 3, 4, 5]);
|
|
1706
|
+
|
|
1707
|
+
// Verify the list maintains insertion order
|
|
1708
|
+
console.log([...list]); // [1, 2, 3, 4, 5];
|
|
1709
|
+
|
|
1710
|
+
// Check length
|
|
1711
|
+
console.log(list.length); // 5;
|
|
1712
|
+
|
|
1713
|
+
// Push a new element to the end
|
|
1714
|
+
list.push(6);
|
|
1715
|
+
console.log(list.length); // 6;
|
|
1716
|
+
console.log([...list]); // [1, 2, 3, 4, 5, 6];
|
|
1717
|
+
```
|
|
1718
|
+
|
|
1719
|
+
#### Overrides
|
|
1720
|
+
|
|
1721
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`push`](LinearLinkedBase.md#push)
|
|
1722
|
+
|
|
1723
|
+
***
|
|
1724
|
+
|
|
1725
|
+
### pushMany()
|
|
1726
|
+
|
|
1727
|
+
```ts
|
|
1728
|
+
pushMany(elements): boolean[];
|
|
1729
|
+
```
|
|
1730
|
+
|
|
1731
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:574](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L574)
|
|
1732
|
+
|
|
1733
|
+
Append a sequence of elements/nodes.
|
|
1734
|
+
|
|
1735
|
+
#### Parameters
|
|
1736
|
+
|
|
1737
|
+
##### elements
|
|
1738
|
+
|
|
1739
|
+
\| `Iterable`\<`E`, `any`, `any`\>
|
|
1740
|
+
\| `Iterable`\<`R`, `any`, `any`\>
|
|
1741
|
+
\| `Iterable`\<[`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\>, `any`, `any`\>
|
|
1742
|
+
|
|
1743
|
+
Iterable of elements or nodes (or raw records if toElementFn is provided).
|
|
1744
|
+
|
|
1745
|
+
#### Returns
|
|
1746
|
+
|
|
1747
|
+
`boolean`[]
|
|
1748
|
+
|
|
1749
|
+
Array of per-element success flags.
|
|
1750
|
+
|
|
1751
|
+
#### Remarks
|
|
1752
|
+
|
|
1753
|
+
Time O(N), Space O(1)
|
|
1754
|
+
|
|
1755
|
+
#### Overrides
|
|
1756
|
+
|
|
1757
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`pushMany`](LinearLinkedBase.md#pushmany)
|
|
1758
|
+
|
|
1759
|
+
***
|
|
1760
|
+
|
|
1761
|
+
### reduce()
|
|
1762
|
+
|
|
1763
|
+
Reduces all elements to a single accumulated value.
|
|
1764
|
+
|
|
1765
|
+
#### Param
|
|
1766
|
+
|
|
1767
|
+
Reducer of signature `(acc, value, index, self) => nextAcc`. The first element is used as the initial accumulator.
|
|
1768
|
+
|
|
1769
|
+
#### Param
|
|
1770
|
+
|
|
1771
|
+
Reducer of signature `(acc, value, index, self) => nextAcc`.
|
|
1772
|
+
|
|
1773
|
+
#### Param
|
|
1774
|
+
|
|
1775
|
+
The initial accumulator value of type `E`.
|
|
1776
|
+
|
|
1777
|
+
#### Template
|
|
1778
|
+
|
|
1779
|
+
The accumulator type when it differs from `E`.
|
|
1780
|
+
|
|
1781
|
+
#### Param
|
|
1782
|
+
|
|
1783
|
+
Reducer of signature `(acc: U, value, index, self) => U`.
|
|
1784
|
+
|
|
1785
|
+
#### Param
|
|
1786
|
+
|
|
1787
|
+
The initial accumulator value of type `U`.
|
|
1788
|
+
|
|
1789
|
+
#### Remarks
|
|
1790
|
+
|
|
1791
|
+
Time O(n), Space O(1). Throws if called on an empty structure without `initialValue`.
|
|
1792
|
+
|
|
1793
|
+
#### Call Signature
|
|
1794
|
+
|
|
1795
|
+
```ts
|
|
1796
|
+
reduce(callbackfn): E;
|
|
1797
|
+
```
|
|
1798
|
+
|
|
1799
|
+
Defined in: [data-structures/base/iterable-element-base.ts:194](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L194)
|
|
1800
|
+
|
|
1801
|
+
##### Parameters
|
|
1802
|
+
|
|
1803
|
+
###### callbackfn
|
|
1804
|
+
|
|
1805
|
+
`ReduceElementCallback`\<`E`, `R`\>
|
|
1806
|
+
|
|
1807
|
+
##### Returns
|
|
1808
|
+
|
|
1809
|
+
`E`
|
|
1810
|
+
|
|
1811
|
+
##### Inherited from
|
|
1812
|
+
|
|
1813
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`reduce`](LinearLinkedBase.md#reduce)
|
|
1814
|
+
|
|
1815
|
+
#### Call Signature
|
|
1816
|
+
|
|
1817
|
+
```ts
|
|
1818
|
+
reduce(callbackfn, initialValue): E;
|
|
1819
|
+
```
|
|
1820
|
+
|
|
1821
|
+
Defined in: [data-structures/base/iterable-element-base.ts:195](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L195)
|
|
1822
|
+
|
|
1823
|
+
##### Parameters
|
|
1824
|
+
|
|
1825
|
+
###### callbackfn
|
|
1826
|
+
|
|
1827
|
+
`ReduceElementCallback`\<`E`, `R`\>
|
|
1828
|
+
|
|
1829
|
+
###### initialValue
|
|
1830
|
+
|
|
1831
|
+
`E`
|
|
1832
|
+
|
|
1833
|
+
##### Returns
|
|
1834
|
+
|
|
1835
|
+
`E`
|
|
1836
|
+
|
|
1837
|
+
##### Inherited from
|
|
1838
|
+
|
|
1839
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`reduce`](LinearLinkedBase.md#reduce)
|
|
1840
|
+
|
|
1841
|
+
#### Call Signature
|
|
1842
|
+
|
|
1843
|
+
```ts
|
|
1844
|
+
reduce<U>(callbackfn, initialValue): U;
|
|
1845
|
+
```
|
|
1846
|
+
|
|
1847
|
+
Defined in: [data-structures/base/iterable-element-base.ts:196](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L196)
|
|
1848
|
+
|
|
1849
|
+
##### Type Parameters
|
|
1850
|
+
|
|
1851
|
+
###### U
|
|
1852
|
+
|
|
1853
|
+
`U`
|
|
1854
|
+
|
|
1855
|
+
##### Parameters
|
|
1856
|
+
|
|
1857
|
+
###### callbackfn
|
|
1858
|
+
|
|
1859
|
+
`ReduceElementCallback`\<`E`, `R`, `U`\>
|
|
1860
|
+
|
|
1861
|
+
###### initialValue
|
|
1862
|
+
|
|
1863
|
+
`U`
|
|
1864
|
+
|
|
1865
|
+
##### Returns
|
|
1866
|
+
|
|
1867
|
+
`U`
|
|
1868
|
+
|
|
1869
|
+
##### Inherited from
|
|
1870
|
+
|
|
1871
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`reduce`](LinearLinkedBase.md#reduce)
|
|
1872
|
+
|
|
1873
|
+
***
|
|
1874
|
+
|
|
1875
|
+
### reduceRight()
|
|
1876
|
+
|
|
1877
|
+
```ts
|
|
1878
|
+
reduceRight<U>(callbackfn, initialValue): U;
|
|
1879
|
+
```
|
|
1880
|
+
|
|
1881
|
+
Defined in: [data-structures/base/linear-base.ts:574](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/linear-base.ts#L574)
|
|
1882
|
+
|
|
1883
|
+
Right-to-left reduction using reverse iterator.
|
|
1884
|
+
|
|
1885
|
+
#### Type Parameters
|
|
1886
|
+
|
|
1887
|
+
##### U
|
|
1888
|
+
|
|
1889
|
+
`U`
|
|
1890
|
+
|
|
1891
|
+
#### Parameters
|
|
1892
|
+
|
|
1893
|
+
##### callbackfn
|
|
1894
|
+
|
|
1895
|
+
`ReduceLinearCallback`\<`E`, `U`\>
|
|
1896
|
+
|
|
1897
|
+
`(acc, element, index, self) => acc`.
|
|
1898
|
+
|
|
1899
|
+
##### initialValue
|
|
1900
|
+
|
|
1901
|
+
`U`
|
|
1902
|
+
|
|
1903
|
+
Initial accumulator.
|
|
1904
|
+
|
|
1905
|
+
#### Returns
|
|
1906
|
+
|
|
1907
|
+
`U`
|
|
1908
|
+
|
|
1909
|
+
Final accumulator.
|
|
1910
|
+
|
|
1911
|
+
#### Remarks
|
|
1912
|
+
|
|
1913
|
+
Time O(n), Space O(1)
|
|
1914
|
+
|
|
1915
|
+
#### Inherited from
|
|
1916
|
+
|
|
1917
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`reduceRight`](LinearLinkedBase.md#reduceright)
|
|
1918
|
+
|
|
1919
|
+
***
|
|
1920
|
+
|
|
1921
|
+
### reverse()
|
|
1922
|
+
|
|
1923
|
+
```ts
|
|
1924
|
+
reverse(): this;
|
|
1925
|
+
```
|
|
1926
|
+
|
|
1927
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:1067](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L1067)
|
|
1928
|
+
|
|
1929
|
+
Reverse the list in place.
|
|
1930
|
+
|
|
1931
|
+
#### Returns
|
|
1932
|
+
|
|
1933
|
+
`this`
|
|
1934
|
+
|
|
1935
|
+
This list.
|
|
1936
|
+
|
|
1937
|
+
*
|
|
1938
|
+
|
|
1939
|
+
#### Remarks
|
|
1940
|
+
|
|
1941
|
+
Time O(N), Space O(1)
|
|
1942
|
+
|
|
1943
|
+
#### Example
|
|
1944
|
+
|
|
1945
|
+
```ts
|
|
1946
|
+
// Reverse the list in-place
|
|
1947
|
+
const list = new SinglyLinkedList<number>([1, 2, 3, 4]);
|
|
1948
|
+
list.reverse();
|
|
1949
|
+
console.log([...list]); // [4, 3, 2, 1];
|
|
1950
|
+
```
|
|
1951
|
+
|
|
1952
|
+
#### Overrides
|
|
1953
|
+
|
|
1954
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`reverse`](LinearLinkedBase.md#reverse)
|
|
1955
|
+
|
|
1956
|
+
***
|
|
1957
|
+
|
|
1958
|
+
### search()
|
|
1959
|
+
|
|
1960
|
+
```ts
|
|
1961
|
+
search(elementNodeOrPredicate): E | undefined;
|
|
1962
|
+
```
|
|
1963
|
+
|
|
1964
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:606](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L606)
|
|
1965
|
+
|
|
1966
|
+
Find the first value matching a predicate (by node).
|
|
1967
|
+
|
|
1968
|
+
#### Parameters
|
|
1969
|
+
|
|
1970
|
+
##### elementNodeOrPredicate
|
|
1971
|
+
|
|
1972
|
+
\| `E`
|
|
1973
|
+
\| [`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\>
|
|
1974
|
+
\| ((`node`) => `boolean`)
|
|
1975
|
+
|
|
1976
|
+
Element, node, or node predicate to match.
|
|
1977
|
+
|
|
1978
|
+
#### Returns
|
|
1979
|
+
|
|
1980
|
+
`E` \| `undefined`
|
|
1981
|
+
|
|
1982
|
+
Matched value or undefined.
|
|
1983
|
+
|
|
1984
|
+
#### Remarks
|
|
1985
|
+
|
|
1986
|
+
Time O(N), Space O(1)
|
|
1987
|
+
|
|
1988
|
+
***
|
|
1989
|
+
|
|
1990
|
+
### setAt()
|
|
1991
|
+
|
|
1992
|
+
```ts
|
|
1993
|
+
setAt(index, value): boolean;
|
|
1994
|
+
```
|
|
1995
|
+
|
|
1996
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:918](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L918)
|
|
1997
|
+
|
|
1998
|
+
Set the element value at an index.
|
|
1999
|
+
|
|
2000
|
+
#### Parameters
|
|
2001
|
+
|
|
2002
|
+
##### index
|
|
2003
|
+
|
|
2004
|
+
`number`
|
|
2005
|
+
|
|
2006
|
+
Zero-based index.
|
|
2007
|
+
|
|
2008
|
+
##### value
|
|
2009
|
+
|
|
2010
|
+
`E`
|
|
2011
|
+
|
|
2012
|
+
New value.
|
|
2013
|
+
|
|
2014
|
+
#### Returns
|
|
2015
|
+
|
|
2016
|
+
`boolean`
|
|
2017
|
+
|
|
2018
|
+
True if updated.
|
|
2019
|
+
|
|
2020
|
+
#### Remarks
|
|
2021
|
+
|
|
2022
|
+
Time O(N), Space O(1)
|
|
2023
|
+
|
|
2024
|
+
#### Overrides
|
|
2025
|
+
|
|
2026
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`setAt`](LinearLinkedBase.md#setat)
|
|
2027
|
+
|
|
2028
|
+
***
|
|
2029
|
+
|
|
2030
|
+
### setEquality()
|
|
2031
|
+
|
|
2032
|
+
```ts
|
|
2033
|
+
setEquality(equals): this;
|
|
2034
|
+
```
|
|
2035
|
+
|
|
2036
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:1235](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L1235)
|
|
2037
|
+
|
|
2038
|
+
Set the equality comparator used to compare values.
|
|
2039
|
+
|
|
2040
|
+
#### Parameters
|
|
2041
|
+
|
|
2042
|
+
##### equals
|
|
2043
|
+
|
|
2044
|
+
(`a`, `b`) => `boolean`
|
|
2045
|
+
|
|
2046
|
+
Equality predicate (a, b) → boolean.
|
|
2047
|
+
|
|
2048
|
+
#### Returns
|
|
2049
|
+
|
|
2050
|
+
`this`
|
|
2051
|
+
|
|
2052
|
+
This list.
|
|
2053
|
+
|
|
2054
|
+
#### Remarks
|
|
2055
|
+
|
|
2056
|
+
Time O(1), Space O(1)
|
|
2057
|
+
|
|
2058
|
+
***
|
|
2059
|
+
|
|
2060
|
+
### shift()
|
|
2061
|
+
|
|
2062
|
+
```ts
|
|
2063
|
+
shift(): E | undefined;
|
|
2064
|
+
```
|
|
2065
|
+
|
|
2066
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:484](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L484)
|
|
2067
|
+
|
|
2068
|
+
Remove and return the head element.
|
|
2069
|
+
|
|
2070
|
+
#### Returns
|
|
2071
|
+
|
|
2072
|
+
`E` \| `undefined`
|
|
2073
|
+
|
|
2074
|
+
Removed element or undefined.
|
|
2075
|
+
|
|
2076
|
+
*
|
|
2077
|
+
|
|
2078
|
+
#### Remarks
|
|
2079
|
+
|
|
2080
|
+
Time O(1), Space O(1)
|
|
2081
|
+
|
|
2082
|
+
#### Example
|
|
2083
|
+
|
|
2084
|
+
```ts
|
|
2085
|
+
// Remove from the front
|
|
2086
|
+
const list = new SinglyLinkedList<number>([10, 20, 30]);
|
|
2087
|
+
console.log(list.shift()); // 10;
|
|
2088
|
+
console.log(list.length); // 2;
|
|
2089
|
+
```
|
|
2090
|
+
|
|
2091
|
+
***
|
|
2092
|
+
|
|
2093
|
+
### slice()
|
|
2094
|
+
|
|
2095
|
+
```ts
|
|
2096
|
+
slice(start?, end?): this;
|
|
2097
|
+
```
|
|
2098
|
+
|
|
2099
|
+
Defined in: [data-structures/base/linear-base.ts:494](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/linear-base.ts#L494)
|
|
2100
|
+
|
|
2101
|
+
Slice via forward iteration (no random access required).
|
|
2102
|
+
|
|
2103
|
+
#### Parameters
|
|
2104
|
+
|
|
2105
|
+
##### start?
|
|
2106
|
+
|
|
2107
|
+
`number` = `0`
|
|
2108
|
+
|
|
2109
|
+
Inclusive start (supports negative index).
|
|
2110
|
+
|
|
2111
|
+
##### end?
|
|
2112
|
+
|
|
2113
|
+
`number` = `...`
|
|
2114
|
+
|
|
2115
|
+
Exclusive end (supports negative index).
|
|
2116
|
+
|
|
2117
|
+
#### Returns
|
|
2118
|
+
|
|
2119
|
+
`this`
|
|
2120
|
+
|
|
2121
|
+
New list (`this` type).
|
|
2122
|
+
|
|
2123
|
+
#### Remarks
|
|
2124
|
+
|
|
2125
|
+
Time O(n), Space O(n)
|
|
2126
|
+
|
|
2127
|
+
#### Inherited from
|
|
2128
|
+
|
|
2129
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`slice`](LinearLinkedBase.md#slice)
|
|
2130
|
+
|
|
2131
|
+
***
|
|
2132
|
+
|
|
2133
|
+
### some()
|
|
2134
|
+
|
|
2135
|
+
```ts
|
|
2136
|
+
some(predicate, thisArg?): boolean;
|
|
2137
|
+
```
|
|
2138
|
+
|
|
2139
|
+
Defined in: [data-structures/base/iterable-element-base.ts:110](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L110)
|
|
2140
|
+
|
|
2141
|
+
Tests whether at least one element satisfies the predicate.
|
|
2142
|
+
|
|
2143
|
+
#### Parameters
|
|
2144
|
+
|
|
2145
|
+
##### predicate
|
|
2146
|
+
|
|
2147
|
+
`ElementCallback`\<`E`, `R`, `boolean`\>
|
|
2148
|
+
|
|
2149
|
+
Function invoked for each element with signature `(value, index, self)`.
|
|
2150
|
+
|
|
2151
|
+
##### thisArg?
|
|
2152
|
+
|
|
2153
|
+
`unknown`
|
|
2154
|
+
|
|
2155
|
+
Optional `this` binding for the predicate.
|
|
2156
|
+
|
|
2157
|
+
#### Returns
|
|
2158
|
+
|
|
2159
|
+
`boolean`
|
|
2160
|
+
|
|
2161
|
+
`true` if any element passes; otherwise `false`.
|
|
2162
|
+
|
|
2163
|
+
#### Remarks
|
|
2164
|
+
|
|
2165
|
+
Time O(n) in the worst case; may exit early on first success. Space O(1).
|
|
2166
|
+
|
|
2167
|
+
#### Inherited from
|
|
2168
|
+
|
|
2169
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`some`](LinearLinkedBase.md#some)
|
|
2170
|
+
|
|
2171
|
+
***
|
|
2172
|
+
|
|
2173
|
+
### sort()
|
|
2174
|
+
|
|
2175
|
+
```ts
|
|
2176
|
+
sort(compareFn?): this;
|
|
2177
|
+
```
|
|
2178
|
+
|
|
2179
|
+
Defined in: [data-structures/base/linear-base.ts:185](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/linear-base.ts#L185)
|
|
2180
|
+
|
|
2181
|
+
In-place stable order via array sort semantics.
|
|
2182
|
+
|
|
2183
|
+
#### Parameters
|
|
2184
|
+
|
|
2185
|
+
##### compareFn?
|
|
2186
|
+
|
|
2187
|
+
(`a`, `b`) => `number`
|
|
2188
|
+
|
|
2189
|
+
Comparator `(a, b) => number`.
|
|
2190
|
+
|
|
2191
|
+
#### Returns
|
|
2192
|
+
|
|
2193
|
+
`this`
|
|
2194
|
+
|
|
2195
|
+
This container.
|
|
2196
|
+
|
|
2197
|
+
#### Remarks
|
|
2198
|
+
|
|
2199
|
+
Time O(n log n), Space O(n) (materializes to array temporarily)
|
|
2200
|
+
|
|
2201
|
+
#### Inherited from
|
|
2202
|
+
|
|
2203
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`sort`](LinearLinkedBase.md#sort)
|
|
2204
|
+
|
|
2205
|
+
***
|
|
2206
|
+
|
|
2207
|
+
### splice()
|
|
2208
|
+
|
|
2209
|
+
```ts
|
|
2210
|
+
splice(
|
|
2211
|
+
start,
|
|
2212
|
+
deleteCount?, ...
|
|
2213
|
+
items?): this;
|
|
2214
|
+
```
|
|
2215
|
+
|
|
2216
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:1161](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L1161)
|
|
2217
|
+
|
|
2218
|
+
Remove and/or insert elements at a position (array-like behavior).
|
|
2219
|
+
|
|
2220
|
+
#### Parameters
|
|
2221
|
+
|
|
2222
|
+
##### start
|
|
2223
|
+
|
|
2224
|
+
`number`
|
|
2225
|
+
|
|
2226
|
+
Start index (clamped to [0, length]).
|
|
2227
|
+
|
|
2228
|
+
##### deleteCount?
|
|
2229
|
+
|
|
2230
|
+
`number` = `0`
|
|
2231
|
+
|
|
2232
|
+
Number of elements to remove (default 0).
|
|
2233
|
+
|
|
2234
|
+
##### items?
|
|
2235
|
+
|
|
2236
|
+
...`E`[]
|
|
2237
|
+
|
|
2238
|
+
Elements to insert after `start`.
|
|
2239
|
+
|
|
2240
|
+
#### Returns
|
|
2241
|
+
|
|
2242
|
+
`this`
|
|
2243
|
+
|
|
2244
|
+
A new list containing the removed elements (typed as `this`).
|
|
2245
|
+
|
|
2246
|
+
#### Remarks
|
|
2247
|
+
|
|
2248
|
+
Time O(N + M), Space O(M)
|
|
2249
|
+
|
|
2250
|
+
#### Overrides
|
|
2251
|
+
|
|
2252
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`splice`](LinearLinkedBase.md#splice)
|
|
2253
|
+
|
|
2254
|
+
***
|
|
2255
|
+
|
|
2256
|
+
### toArray()
|
|
2257
|
+
|
|
2258
|
+
```ts
|
|
2259
|
+
toArray(): E[];
|
|
2260
|
+
```
|
|
2261
|
+
|
|
2262
|
+
Defined in: [data-structures/base/iterable-element-base.ts:246](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L246)
|
|
2263
|
+
|
|
2264
|
+
Materializes the elements into a new array.
|
|
2265
|
+
|
|
2266
|
+
#### Returns
|
|
2267
|
+
|
|
2268
|
+
`E`[]
|
|
2269
|
+
|
|
2270
|
+
A shallow array copy of the iteration order.
|
|
2271
|
+
|
|
2272
|
+
#### Remarks
|
|
2273
|
+
|
|
2274
|
+
Time O(n), Space O(n).
|
|
2275
|
+
|
|
2276
|
+
#### Inherited from
|
|
2277
|
+
|
|
2278
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`toArray`](LinearLinkedBase.md#toarray)
|
|
2279
|
+
|
|
2280
|
+
***
|
|
2281
|
+
|
|
2282
|
+
### toReversedArray()
|
|
2283
|
+
|
|
2284
|
+
```ts
|
|
2285
|
+
toReversedArray(): E[];
|
|
2286
|
+
```
|
|
2287
|
+
|
|
2288
|
+
Defined in: [data-structures/base/linear-base.ts:237](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/linear-base.ts#L237)
|
|
2289
|
+
|
|
2290
|
+
Snapshot elements into a reversed array.
|
|
2291
|
+
|
|
2292
|
+
#### Returns
|
|
2293
|
+
|
|
2294
|
+
`E`[]
|
|
2295
|
+
|
|
2296
|
+
New reversed array.
|
|
2297
|
+
|
|
2298
|
+
#### Remarks
|
|
2299
|
+
|
|
2300
|
+
Time O(n), Space O(n)
|
|
2301
|
+
|
|
2302
|
+
#### Inherited from
|
|
2303
|
+
|
|
2304
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`toReversedArray`](LinearLinkedBase.md#toreversedarray)
|
|
2305
|
+
|
|
2306
|
+
***
|
|
2307
|
+
|
|
2308
|
+
### toVisual()
|
|
2309
|
+
|
|
2310
|
+
```ts
|
|
2311
|
+
toVisual(): E[];
|
|
2312
|
+
```
|
|
2313
|
+
|
|
2314
|
+
Defined in: [data-structures/base/iterable-element-base.ts:258](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L258)
|
|
2315
|
+
|
|
2316
|
+
Returns a representation of the structure suitable for quick visualization.
|
|
2317
|
+
Defaults to an array of elements; subclasses may override to provide richer visuals.
|
|
2318
|
+
|
|
2319
|
+
#### Returns
|
|
2320
|
+
|
|
2321
|
+
`E`[]
|
|
2322
|
+
|
|
2323
|
+
A visual representation (array by default).
|
|
2324
|
+
|
|
2325
|
+
#### Remarks
|
|
2326
|
+
|
|
2327
|
+
Time O(n), Space O(n).
|
|
2328
|
+
|
|
2329
|
+
#### Inherited from
|
|
2330
|
+
|
|
2331
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`toVisual`](LinearLinkedBase.md#tovisual)
|
|
2332
|
+
|
|
2333
|
+
***
|
|
2334
|
+
|
|
2335
|
+
### unshift()
|
|
2336
|
+
|
|
2337
|
+
```ts
|
|
2338
|
+
unshift(elementOrNode): boolean;
|
|
2339
|
+
```
|
|
2340
|
+
|
|
2341
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:555](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L555)
|
|
2342
|
+
|
|
2343
|
+
Prepend an element/node to the head.
|
|
2344
|
+
|
|
2345
|
+
#### Parameters
|
|
2346
|
+
|
|
2347
|
+
##### elementOrNode
|
|
2348
|
+
|
|
2349
|
+
`E` \| [`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\>
|
|
2350
|
+
|
|
2351
|
+
Element or node to prepend.
|
|
2352
|
+
|
|
2353
|
+
#### Returns
|
|
2354
|
+
|
|
2355
|
+
`boolean`
|
|
2356
|
+
|
|
2357
|
+
True when prepended.
|
|
2358
|
+
|
|
2359
|
+
*
|
|
2360
|
+
|
|
2361
|
+
#### Remarks
|
|
2362
|
+
|
|
2363
|
+
Time O(1), Space O(1)
|
|
2364
|
+
|
|
2365
|
+
#### Example
|
|
2366
|
+
|
|
2367
|
+
```ts
|
|
2368
|
+
// SinglyLinkedList unshift and forward traversal
|
|
2369
|
+
const list = new SinglyLinkedList<number>([20, 30, 40]);
|
|
2370
|
+
|
|
2371
|
+
// Unshift adds to the beginning
|
|
2372
|
+
list.unshift(10);
|
|
2373
|
+
console.log([...list]); // [10, 20, 30, 40];
|
|
2374
|
+
|
|
2375
|
+
// Access elements (forward traversal only for singly linked)
|
|
2376
|
+
const second = list.at(1);
|
|
2377
|
+
console.log(second); // 20;
|
|
2378
|
+
|
|
2379
|
+
// SinglyLinkedList allows forward iteration only
|
|
2380
|
+
const elements: number[] = [];
|
|
2381
|
+
for (const item of list) {
|
|
2382
|
+
elements.push(item);
|
|
2383
|
+
}
|
|
2384
|
+
console.log(elements); // [10, 20, 30, 40];
|
|
2385
|
+
|
|
2386
|
+
console.log(list.length); // 4;
|
|
2387
|
+
```
|
|
2388
|
+
|
|
2389
|
+
***
|
|
2390
|
+
|
|
2391
|
+
### unshiftMany()
|
|
2392
|
+
|
|
2393
|
+
```ts
|
|
2394
|
+
unshiftMany(elements): boolean[];
|
|
2395
|
+
```
|
|
2396
|
+
|
|
2397
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:590](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L590)
|
|
2398
|
+
|
|
2399
|
+
Prepend a sequence of elements/nodes.
|
|
2400
|
+
|
|
2401
|
+
#### Parameters
|
|
2402
|
+
|
|
2403
|
+
##### elements
|
|
2404
|
+
|
|
2405
|
+
\| `Iterable`\<`E`, `any`, `any`\>
|
|
2406
|
+
\| `Iterable`\<`R`, `any`, `any`\>
|
|
2407
|
+
\| `Iterable`\<[`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\>, `any`, `any`\>
|
|
2408
|
+
|
|
2409
|
+
Iterable of elements or nodes (or raw records if toElementFn is provided).
|
|
2410
|
+
|
|
2411
|
+
#### Returns
|
|
2412
|
+
|
|
2413
|
+
`boolean`[]
|
|
2414
|
+
|
|
2415
|
+
Array of per-element success flags.
|
|
2416
|
+
|
|
2417
|
+
#### Remarks
|
|
2418
|
+
|
|
2419
|
+
Time O(N), Space O(1)
|
|
2420
|
+
|
|
2421
|
+
***
|
|
2422
|
+
|
|
2423
|
+
### values()
|
|
2424
|
+
|
|
2425
|
+
```ts
|
|
2426
|
+
values(): IterableIterator<E>;
|
|
2427
|
+
```
|
|
2428
|
+
|
|
2429
|
+
Defined in: [data-structures/base/iterable-element-base.ts:72](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L72)
|
|
2430
|
+
|
|
2431
|
+
Returns an iterator over the values (alias of the default iterator).
|
|
2432
|
+
|
|
2433
|
+
#### Returns
|
|
2434
|
+
|
|
2435
|
+
`IterableIterator`\<`E`\>
|
|
2436
|
+
|
|
2437
|
+
An `IterableIterator<E>` over all elements.
|
|
2438
|
+
|
|
2439
|
+
#### Remarks
|
|
2440
|
+
|
|
2441
|
+
Creating the iterator is O(1); full iteration is Time O(n), Space O(1).
|
|
2442
|
+
|
|
2443
|
+
#### Inherited from
|
|
2444
|
+
|
|
2445
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`values`](LinearLinkedBase.md#values)
|
|
2446
|
+
|
|
2447
|
+
***
|
|
2448
|
+
|
|
2449
|
+
### from()
|
|
2450
|
+
|
|
2451
|
+
```ts
|
|
2452
|
+
static from<E, R, S>(
|
|
2453
|
+
this,
|
|
2454
|
+
data,
|
|
2455
|
+
options?): S;
|
|
2456
|
+
```
|
|
2457
|
+
|
|
2458
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:281](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L281)
|
|
2459
|
+
|
|
2460
|
+
Create a new list from an iterable of elements.
|
|
2461
|
+
|
|
2462
|
+
#### Type Parameters
|
|
2463
|
+
|
|
2464
|
+
##### E
|
|
2465
|
+
|
|
2466
|
+
`E`
|
|
2467
|
+
|
|
2468
|
+
##### R
|
|
2469
|
+
|
|
2470
|
+
`R` = `any`
|
|
2471
|
+
|
|
2472
|
+
##### S
|
|
2473
|
+
|
|
2474
|
+
`S` *extends* `SinglyLinkedList`\<`E`, `R`\> = `SinglyLinkedList`\<`E`, `R`\>
|
|
2475
|
+
|
|
2476
|
+
#### Parameters
|
|
2477
|
+
|
|
2478
|
+
##### this
|
|
2479
|
+
|
|
2480
|
+
`Object`
|
|
2481
|
+
|
|
2482
|
+
The constructor (subclass) to instantiate.
|
|
2483
|
+
|
|
2484
|
+
##### data
|
|
2485
|
+
|
|
2486
|
+
`Iterable`\<`E`\>
|
|
2487
|
+
|
|
2488
|
+
Iterable of elements to insert.
|
|
2489
|
+
|
|
2490
|
+
##### options?
|
|
2491
|
+
|
|
2492
|
+
`SinglyLinkedListOptions`\<`E`, `R`\>
|
|
2493
|
+
|
|
2494
|
+
Options forwarded to the constructor.
|
|
2495
|
+
|
|
2496
|
+
#### Returns
|
|
2497
|
+
|
|
2498
|
+
`S`
|
|
2499
|
+
|
|
2500
|
+
A new list populated with the iterable's elements.
|
|
2501
|
+
|
|
2502
|
+
#### Remarks
|
|
2503
|
+
|
|
2504
|
+
Time O(N), Space O(N)
|
|
2505
|
+
|
|
2506
|
+
|
|
2507
|
+
---
|
|
2508
|
+
|
|
2509
|
+
## Protected Members
|
|
2510
|
+
|
|
2511
|
+
### \_toElementFn?
|
|
2512
|
+
|
|
2513
|
+
```ts
|
|
2514
|
+
protected optional _toElementFn?: (rawElement) => E;
|
|
2515
|
+
```
|
|
2516
|
+
|
|
2517
|
+
Defined in: [data-structures/base/iterable-element-base.ts:39](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-element-base.ts#L39)
|
|
2518
|
+
|
|
2519
|
+
The converter used to transform a raw element (`R`) into a public element (`E`).
|
|
2520
|
+
|
|
2521
|
+
#### Parameters
|
|
2522
|
+
|
|
2523
|
+
##### rawElement
|
|
2524
|
+
|
|
2525
|
+
`R`
|
|
2526
|
+
|
|
2527
|
+
#### Returns
|
|
2528
|
+
|
|
2529
|
+
`E`
|
|
2530
|
+
|
|
2531
|
+
#### Remarks
|
|
2532
|
+
|
|
2533
|
+
Time O(1), Space O(1).
|
|
2534
|
+
|
|
2535
|
+
#### Inherited from
|
|
2536
|
+
|
|
2537
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`_toElementFn`](LinearLinkedBase.md#_toelementfn)
|
|
2538
|
+
|
|
2539
|
+
## Accessors
|
|
2540
|
+
|
|
2541
|
+
### \_createInstance()
|
|
2542
|
+
|
|
2543
|
+
```ts
|
|
2544
|
+
protected _createInstance(options?): this;
|
|
2545
|
+
```
|
|
2546
|
+
|
|
2547
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:1578](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L1578)
|
|
2548
|
+
|
|
2549
|
+
(Protected) Create an empty instance of the same concrete class.
|
|
2550
|
+
|
|
2551
|
+
#### Parameters
|
|
2552
|
+
|
|
2553
|
+
##### options?
|
|
2554
|
+
|
|
2555
|
+
`SinglyLinkedListOptions`\<`E`, `R`\>
|
|
2556
|
+
|
|
2557
|
+
Options forwarded to the constructor.
|
|
2558
|
+
|
|
2559
|
+
#### Returns
|
|
2560
|
+
|
|
2561
|
+
`this`
|
|
2562
|
+
|
|
2563
|
+
An empty like-kind list instance.
|
|
2564
|
+
|
|
2565
|
+
#### Remarks
|
|
2566
|
+
|
|
2567
|
+
Time O(1), Space O(1)
|
|
2568
|
+
|
|
2569
|
+
#### Overrides
|
|
2570
|
+
|
|
2571
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`_createInstance`](LinearLinkedBase.md#_createinstance)
|
|
2572
|
+
|
|
2573
|
+
***
|
|
2574
|
+
|
|
2575
|
+
### \_createLike()
|
|
2576
|
+
|
|
2577
|
+
```ts
|
|
2578
|
+
protected _createLike<EM, RM>(elements?, options?): SinglyLinkedList<EM, RM>;
|
|
2579
|
+
```
|
|
2580
|
+
|
|
2581
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:1596](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L1596)
|
|
2582
|
+
|
|
2583
|
+
(Protected) Create a like-kind instance and seed it from an iterable.
|
|
2584
|
+
|
|
2585
|
+
#### Type Parameters
|
|
2586
|
+
|
|
2587
|
+
##### EM
|
|
2588
|
+
|
|
2589
|
+
`EM`
|
|
2590
|
+
|
|
2591
|
+
##### RM
|
|
2592
|
+
|
|
2593
|
+
`RM`
|
|
2594
|
+
|
|
2595
|
+
#### Parameters
|
|
2596
|
+
|
|
2597
|
+
##### elements?
|
|
2598
|
+
|
|
2599
|
+
\| `Iterable`\<`EM`, `any`, `any`\>
|
|
2600
|
+
\| `Iterable`\<`RM`, `any`, `any`\>
|
|
2601
|
+
\| `Iterable`\<[`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`EM`\>, `any`, `any`\>
|
|
2602
|
+
|
|
2603
|
+
Iterable used to seed the new list.
|
|
2604
|
+
|
|
2605
|
+
##### options?
|
|
2606
|
+
|
|
2607
|
+
`SinglyLinkedListOptions`\<`EM`, `RM`\>
|
|
2608
|
+
|
|
2609
|
+
Options forwarded to the constructor.
|
|
2610
|
+
|
|
2611
|
+
#### Returns
|
|
2612
|
+
|
|
2613
|
+
`SinglyLinkedList`\<`EM`, `RM`\>
|
|
2614
|
+
|
|
2615
|
+
A like-kind SinglyLinkedList instance.
|
|
2616
|
+
|
|
2617
|
+
#### Remarks
|
|
2618
|
+
|
|
2619
|
+
Time O(N), Space O(N)
|
|
2620
|
+
|
|
2621
|
+
***
|
|
2622
|
+
|
|
2623
|
+
### \_ensureNode()
|
|
2624
|
+
|
|
2625
|
+
```ts
|
|
2626
|
+
protected _ensureNode(elementOrNode): SinglyLinkedListNode<E>;
|
|
2627
|
+
```
|
|
2628
|
+
|
|
2629
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:1497](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L1497)
|
|
2630
|
+
|
|
2631
|
+
(Protected) Normalize input into a node instance.
|
|
2632
|
+
|
|
2633
|
+
#### Parameters
|
|
2634
|
+
|
|
2635
|
+
##### elementOrNode
|
|
2636
|
+
|
|
2637
|
+
`E` \| [`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\>
|
|
2638
|
+
|
|
2639
|
+
Element or node.
|
|
2640
|
+
|
|
2641
|
+
#### Returns
|
|
2642
|
+
|
|
2643
|
+
[`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\>
|
|
2644
|
+
|
|
2645
|
+
A SinglyLinkedListNode for the provided input.
|
|
2646
|
+
|
|
2647
|
+
#### Remarks
|
|
2648
|
+
|
|
2649
|
+
Time O(1), Space O(1)
|
|
2650
|
+
|
|
2651
|
+
***
|
|
2652
|
+
|
|
2653
|
+
### \_ensurePredicate()
|
|
2654
|
+
|
|
2655
|
+
```ts
|
|
2656
|
+
protected _ensurePredicate(elementNodeOrPredicate): (node) => boolean;
|
|
2657
|
+
```
|
|
2658
|
+
|
|
2659
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:1509](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L1509)
|
|
2660
|
+
|
|
2661
|
+
(Protected) Normalize input into a node predicate.
|
|
2662
|
+
|
|
2663
|
+
#### Parameters
|
|
2664
|
+
|
|
2665
|
+
##### elementNodeOrPredicate
|
|
2666
|
+
|
|
2667
|
+
\| `E`
|
|
2668
|
+
\| [`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\>
|
|
2669
|
+
\| ((`node`) => `boolean`)
|
|
2670
|
+
|
|
2671
|
+
Element, node, or predicate.
|
|
2672
|
+
|
|
2673
|
+
#### Returns
|
|
2674
|
+
|
|
2675
|
+
A predicate taking a node and returning true/false.
|
|
2676
|
+
|
|
2677
|
+
(`node`) => `boolean`
|
|
2678
|
+
|
|
2679
|
+
#### Remarks
|
|
2680
|
+
|
|
2681
|
+
Time O(1), Space O(1)
|
|
2682
|
+
|
|
2683
|
+
***
|
|
2684
|
+
|
|
2685
|
+
### \_getIterator()
|
|
2686
|
+
|
|
2687
|
+
```ts
|
|
2688
|
+
protected _getIterator(): IterableIterator<E>;
|
|
2689
|
+
```
|
|
2690
|
+
|
|
2691
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:1538](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L1538)
|
|
2692
|
+
|
|
2693
|
+
(Protected) Iterate values from head to tail.
|
|
2694
|
+
|
|
2695
|
+
#### Returns
|
|
2696
|
+
|
|
2697
|
+
`IterableIterator`\<`E`\>
|
|
2698
|
+
|
|
2699
|
+
Iterator of values (E).
|
|
2700
|
+
|
|
2701
|
+
#### Remarks
|
|
2702
|
+
|
|
2703
|
+
Time O(N), Space O(1)
|
|
2704
|
+
|
|
2705
|
+
#### Overrides
|
|
2706
|
+
|
|
2707
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`_getIterator`](LinearLinkedBase.md#_getiterator)
|
|
2708
|
+
|
|
2709
|
+
***
|
|
2710
|
+
|
|
2711
|
+
### \_getNodeIterator()
|
|
2712
|
+
|
|
2713
|
+
```ts
|
|
2714
|
+
protected _getNodeIterator(): IterableIterator<SinglyLinkedListNode<E>>;
|
|
2715
|
+
```
|
|
2716
|
+
|
|
2717
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:1563](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L1563)
|
|
2718
|
+
|
|
2719
|
+
(Protected) Iterate nodes from head to tail.
|
|
2720
|
+
|
|
2721
|
+
#### Returns
|
|
2722
|
+
|
|
2723
|
+
`IterableIterator`\<[`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\>\>
|
|
2724
|
+
|
|
2725
|
+
Iterator of nodes.
|
|
2726
|
+
|
|
2727
|
+
#### Remarks
|
|
2728
|
+
|
|
2729
|
+
Time O(N), Space O(1)
|
|
2730
|
+
|
|
2731
|
+
#### Overrides
|
|
2732
|
+
|
|
2733
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`_getNodeIterator`](LinearLinkedBase.md#_getnodeiterator)
|
|
2734
|
+
|
|
2735
|
+
***
|
|
2736
|
+
|
|
2737
|
+
### \_getPrevNode()
|
|
2738
|
+
|
|
2739
|
+
```ts
|
|
2740
|
+
protected _getPrevNode(node): SinglyLinkedListNode<E> | undefined;
|
|
2741
|
+
```
|
|
2742
|
+
|
|
2743
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:1525](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L1525)
|
|
2744
|
+
|
|
2745
|
+
(Protected) Get the previous node of a given node.
|
|
2746
|
+
|
|
2747
|
+
#### Parameters
|
|
2748
|
+
|
|
2749
|
+
##### node
|
|
2750
|
+
|
|
2751
|
+
[`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\>
|
|
2752
|
+
|
|
2753
|
+
A node in the list.
|
|
2754
|
+
|
|
2755
|
+
#### Returns
|
|
2756
|
+
|
|
2757
|
+
[`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\> \| `undefined`
|
|
2758
|
+
|
|
2759
|
+
Previous node or undefined.
|
|
2760
|
+
|
|
2761
|
+
#### Remarks
|
|
2762
|
+
|
|
2763
|
+
Time O(N), Space O(1)
|
|
2764
|
+
|
|
2765
|
+
#### Overrides
|
|
2766
|
+
|
|
2767
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`_getPrevNode`](LinearLinkedBase.md#_getprevnode)
|
|
2768
|
+
|
|
2769
|
+
***
|
|
2770
|
+
|
|
2771
|
+
### \_getReverseIterator()
|
|
2772
|
+
|
|
2773
|
+
```ts
|
|
2774
|
+
protected _getReverseIterator(): IterableIterator<E>;
|
|
2775
|
+
```
|
|
2776
|
+
|
|
2777
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:1552](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L1552)
|
|
2778
|
+
|
|
2779
|
+
(Protected) Iterate values from tail to head.
|
|
2780
|
+
|
|
2781
|
+
#### Returns
|
|
2782
|
+
|
|
2783
|
+
`IterableIterator`\<`E`\>
|
|
2784
|
+
|
|
2785
|
+
Iterator of values (E).
|
|
2786
|
+
|
|
2787
|
+
#### Remarks
|
|
2788
|
+
|
|
2789
|
+
Time O(N), Space O(N)
|
|
2790
|
+
|
|
2791
|
+
#### Overrides
|
|
2792
|
+
|
|
2793
|
+
[`LinearLinkedBase`](LinearLinkedBase.md).[`_getReverseIterator`](LinearLinkedBase.md#_getreverseiterator)
|
|
2794
|
+
|
|
2795
|
+
***
|
|
2796
|
+
|
|
2797
|
+
### \_isPredicate()
|
|
2798
|
+
|
|
2799
|
+
```ts
|
|
2800
|
+
protected _isPredicate(elementNodeOrPredicate): elementNodeOrPredicate is (node: SinglyLinkedListNode<E>) => boolean;
|
|
2801
|
+
```
|
|
2802
|
+
|
|
2803
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:1484](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L1484)
|
|
2804
|
+
|
|
2805
|
+
(Protected) Check if input is a node predicate function.
|
|
2806
|
+
|
|
2807
|
+
#### Parameters
|
|
2808
|
+
|
|
2809
|
+
##### elementNodeOrPredicate
|
|
2810
|
+
|
|
2811
|
+
\| `E`
|
|
2812
|
+
\| [`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\>
|
|
2813
|
+
\| ((`node`) => `boolean`)
|
|
2814
|
+
|
|
2815
|
+
Element, node, or node predicate.
|
|
2816
|
+
|
|
2817
|
+
#### Returns
|
|
2818
|
+
|
|
2819
|
+
`elementNodeOrPredicate is (node: SinglyLinkedListNode<E>) => boolean`
|
|
2820
|
+
|
|
2821
|
+
True if input is a predicate function.
|
|
2822
|
+
|
|
2823
|
+
#### Remarks
|
|
2824
|
+
|
|
2825
|
+
Time O(1), Space O(1)
|
|
2826
|
+
|
|
2827
|
+
***
|
|
2828
|
+
|
|
2829
|
+
### \_spawnLike()
|
|
2830
|
+
|
|
2831
|
+
```ts
|
|
2832
|
+
protected _spawnLike<EM, RM>(options?): SinglyLinkedList<EM, RM>;
|
|
2833
|
+
```
|
|
2834
|
+
|
|
2835
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:1616](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L1616)
|
|
2836
|
+
|
|
2837
|
+
(Protected) Spawn an empty like-kind list instance.
|
|
2838
|
+
|
|
2839
|
+
#### Type Parameters
|
|
2840
|
+
|
|
2841
|
+
##### EM
|
|
2842
|
+
|
|
2843
|
+
`EM`
|
|
2844
|
+
|
|
2845
|
+
##### RM
|
|
2846
|
+
|
|
2847
|
+
`RM`
|
|
2848
|
+
|
|
2849
|
+
#### Parameters
|
|
2850
|
+
|
|
2851
|
+
##### options?
|
|
2852
|
+
|
|
2853
|
+
`SinglyLinkedListOptions`\<`EM`, `RM`\>
|
|
2854
|
+
|
|
2855
|
+
Options forwarded to the constructor.
|
|
2856
|
+
|
|
2857
|
+
#### Returns
|
|
2858
|
+
|
|
2859
|
+
`SinglyLinkedList`\<`EM`, `RM`\>
|
|
2860
|
+
|
|
2861
|
+
An empty like-kind SinglyLinkedList instance.
|
|
2862
|
+
|
|
2863
|
+
#### Remarks
|
|
2864
|
+
|
|
2865
|
+
Time O(1), Space O(1)
|
|
2866
|
+
|
|
2867
|
+
***
|
|
2868
|
+
|
|
2869
|
+
### createNode()
|
|
2870
|
+
|
|
2871
|
+
```ts
|
|
2872
|
+
protected createNode(value): SinglyLinkedListNode<E>;
|
|
2873
|
+
```
|
|
2874
|
+
|
|
2875
|
+
Defined in: [data-structures/linked-list/singly-linked-list.ts:1473](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/linked-list/singly-linked-list.ts#L1473)
|
|
2876
|
+
|
|
2877
|
+
(Protected) Create a node from a value.
|
|
2878
|
+
|
|
2879
|
+
#### Parameters
|
|
2880
|
+
|
|
2881
|
+
##### value
|
|
2882
|
+
|
|
2883
|
+
`E`
|
|
2884
|
+
|
|
2885
|
+
Value to wrap in a node.
|
|
2886
|
+
|
|
2887
|
+
#### Returns
|
|
2888
|
+
|
|
2889
|
+
[`SinglyLinkedListNode`](SinglyLinkedListNode.md)\<`E`\>
|
|
2890
|
+
|
|
2891
|
+
A new SinglyLinkedListNode instance.
|
|
2892
|
+
|
|
2893
|
+
#### Remarks
|
|
2894
|
+
|
|
2895
|
+
Time O(1), Space O(1)
|
|
2896
|
+
|
|
2897
|
+
***
|