data-structure-typed 1.16.1 → 1.17.3

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.
Files changed (100) hide show
  1. package/README.md +1 -1
  2. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +178 -70
  3. package/dist/data-structures/linked-list/doubly-linked-list.js +475 -244
  4. package/dist/data-structures/linked-list/index.d.ts +1 -0
  5. package/dist/data-structures/linked-list/index.js +1 -0
  6. package/dist/data-structures/linked-list/singly-linked-list.d.ts +111 -248
  7. package/dist/data-structures/linked-list/singly-linked-list.js +338 -619
  8. package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -1
  9. package/dist/data-structures/linked-list/skip-linked-list.js +7 -0
  10. package/dist/data-structures/matrix/vector2d.js +2 -2
  11. package/dist/data-structures/types/binary-tree.d.ts +0 -5
  12. package/docs/assets/search.js +1 -1
  13. package/docs/classes/AVLTree.html +94 -94
  14. package/docs/classes/AVLTreeNode.html +37 -37
  15. package/docs/classes/AaTree.html +2 -2
  16. package/docs/classes/AbstractEdge.html +12 -12
  17. package/docs/classes/AbstractGraph.html +30 -30
  18. package/docs/classes/AbstractVertex.html +7 -7
  19. package/docs/classes/ArrayDeque.html +15 -15
  20. package/docs/classes/BST.html +87 -87
  21. package/docs/classes/BSTNode.html +37 -37
  22. package/docs/classes/BTree.html +2 -2
  23. package/docs/classes/BinaryIndexedTree.html +8 -8
  24. package/docs/classes/BinaryTree.html +83 -83
  25. package/docs/classes/BinaryTreeNode.html +37 -37
  26. package/docs/classes/Character.html +5 -5
  27. package/docs/classes/CoordinateMap.html +11 -11
  28. package/docs/classes/CoordinateSet.html +10 -10
  29. package/docs/classes/Deque.html +564 -356
  30. package/docs/classes/DirectedEdge.html +18 -18
  31. package/docs/classes/DirectedGraph.html +42 -42
  32. package/docs/classes/DirectedVertex.html +7 -7
  33. package/docs/classes/DoublyLinkedList.html +546 -313
  34. package/docs/classes/DoublyLinkedListNode.html +53 -36
  35. package/docs/classes/Heap.html +21 -21
  36. package/docs/classes/HeapItem.html +9 -9
  37. package/docs/classes/Matrix2D.html +17 -17
  38. package/docs/classes/MatrixNTI2D.html +5 -5
  39. package/docs/classes/MaxHeap.html +21 -21
  40. package/docs/classes/MaxPriorityQueue.html +35 -35
  41. package/docs/classes/MinHeap.html +21 -21
  42. package/docs/classes/MinPriorityQueue.html +35 -35
  43. package/docs/classes/Navigator.html +11 -11
  44. package/docs/classes/ObjectDeque.html +26 -26
  45. package/docs/classes/PriorityQueue.html +33 -33
  46. package/docs/classes/Queue.html +15 -15
  47. package/docs/classes/RBTree.html +2 -2
  48. package/docs/classes/SegmentTree.html +13 -13
  49. package/docs/classes/SegmentTreeNode.html +27 -27
  50. package/docs/classes/SinglyLinkedList.html +277 -606
  51. package/docs/classes/SinglyLinkedListNode.html +40 -167
  52. package/docs/classes/SkipLinkedList.html +150 -0
  53. package/docs/classes/SplayTree.html +2 -2
  54. package/docs/classes/Stack.html +13 -13
  55. package/docs/classes/TreeMultiSet.html +87 -87
  56. package/docs/classes/TreeNode.html +9 -9
  57. package/docs/classes/Trie.html +14 -14
  58. package/docs/classes/TrieNode.html +12 -12
  59. package/docs/classes/TwoThreeTree.html +2 -2
  60. package/docs/classes/UndirectedEdge.html +14 -14
  61. package/docs/classes/UndirectedGraph.html +36 -36
  62. package/docs/classes/UndirectedVertex.html +7 -7
  63. package/docs/classes/Vector2D.html +29 -29
  64. package/docs/enums/CP.html +5 -5
  65. package/docs/enums/FamilyPosition.html +5 -5
  66. package/docs/enums/LoopType.html +4 -4
  67. package/docs/index.html +3 -3
  68. package/docs/interfaces/AVLTreeDeleted.html +4 -4
  69. package/docs/interfaces/HeapOptions.html +3 -3
  70. package/docs/interfaces/IDirectedGraph.html +8 -8
  71. package/docs/interfaces/IGraph.html +20 -20
  72. package/docs/interfaces/NavigatorParams.html +6 -6
  73. package/docs/interfaces/PriorityQueueOptions.html +5 -5
  74. package/docs/modules.html +2 -2
  75. package/docs/types/BSTComparator.html +2 -2
  76. package/docs/types/BSTDeletedResult.html +2 -2
  77. package/docs/types/BinaryTreeDeleted.html +2 -2
  78. package/docs/types/BinaryTreeNodeId.html +2 -2
  79. package/docs/types/BinaryTreeNodePropertyName.html +2 -2
  80. package/docs/types/DFSOrderPattern.html +2 -2
  81. package/docs/types/DijkstraResult.html +2 -2
  82. package/docs/types/Direction.html +2 -2
  83. package/docs/types/DoublyLinkedListGetBy.html +2 -2
  84. package/docs/types/NodeOrPropertyName.html +2 -2
  85. package/docs/types/PriorityQueueComparator.html +2 -2
  86. package/docs/types/PriorityQueueDFSOrderPattern.html +2 -2
  87. package/docs/types/ResultByProperty.html +2 -2
  88. package/docs/types/ResultsByProperty.html +2 -2
  89. package/docs/types/SegmentTreeNodeVal.html +2 -2
  90. package/docs/types/SpecifyOptional.html +2 -2
  91. package/docs/types/Thunk.html +2 -2
  92. package/docs/types/ToThunkFn.html +2 -2
  93. package/docs/types/TopologicalStatus.html +2 -2
  94. package/docs/types/TreeMultiSetDeletedResult.html +2 -2
  95. package/docs/types/TrlAsyncFn.html +2 -2
  96. package/docs/types/TrlFn.html +2 -2
  97. package/docs/types/Turning.html +2 -2
  98. package/docs/types/VertexId.html +2 -2
  99. package/package.json +1 -3
  100. package/docs/interfaces/BinaryTreeNodeObj.html +0 -168
@@ -1,2 +1,3 @@
1
1
  export * from './singly-linked-list';
2
2
  export * from './doubly-linked-list';
3
+ export * from './skip-linked-list';
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./singly-linked-list"), exports);
18
18
  __exportStar(require("./doubly-linked-list"), exports);
19
+ __exportStar(require("./skip-linked-list"), exports);
@@ -5,290 +5,153 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- export declare class SinglyLinkedListNode<NodeVal = any> {
9
- constructor(val: NodeVal, prev?: SinglyLinkedListNode<NodeVal> | null, next?: SinglyLinkedListNode<NodeVal> | null, list?: SinglyLinkedList<NodeVal> | null);
10
- protected _val: NodeVal;
11
- get val(): NodeVal;
12
- set val(value: NodeVal);
13
- protected _prev: SinglyLinkedListNode<NodeVal> | null;
14
- get prev(): SinglyLinkedListNode<NodeVal> | null;
15
- set prev(value: SinglyLinkedListNode<NodeVal> | null);
16
- protected _next: SinglyLinkedListNode<NodeVal> | null;
17
- get next(): SinglyLinkedListNode<NodeVal> | null;
18
- set next(value: SinglyLinkedListNode<NodeVal> | null);
19
- protected _list: SinglyLinkedList<NodeVal> | null;
20
- get list(): SinglyLinkedList<NodeVal> | null;
21
- set list(value: SinglyLinkedList<NodeVal> | null);
22
- get index(): number | undefined;
23
- /**
24
- * The `insertBefore` function inserts a new node with the given value before the current node in a singly linked list.
25
- * @param {NodeVal} val - The parameter "val" is of type "NodeVal". It represents the value of the node that you want
26
- * to insert before the current node.
27
- * @returns The method is returning a SinglyLinkedList<NodeVal>.
28
- */
29
- insertBefore(val: NodeVal): SinglyLinkedList<NodeVal>;
30
- /**
31
- * The function inserts a new node with the given value after the current node in a singly linked list.
32
- * @param {NodeVal} val - The parameter `val` is the value of the node that you want to insert after the current node.
33
- * @returns The method is returning a SinglyLinkedList<NodeVal>.
34
- */
35
- insertAfter(val: NodeVal): SinglyLinkedList<NodeVal>;
36
- /**
37
- * The `remove()` function removes a node from a singly linked list.
38
- * @returns The remove() method is returning a SinglyLinkedListNode<NodeVal> object.
39
- */
40
- remove(): SinglyLinkedListNode<NodeVal>;
8
+ export declare class SinglyLinkedListNode<T = number> {
9
+ /**
10
+ * The constructor function initializes an instance of a class with a given value and sets the next property to null.
11
+ * @param {T} val - The "val" parameter is of type T, which means it can be any data type. It represents the value that
12
+ * will be stored in the node of a linked list.
13
+ */
14
+ constructor(val: T);
15
+ private _val;
16
+ get val(): T;
17
+ set val(value: T);
18
+ private _next;
19
+ get next(): SinglyLinkedListNode<T> | null;
20
+ set next(value: SinglyLinkedListNode<T> | null);
41
21
  }
42
- export declare class SinglyLinkedList<NodeVal = any> {
43
- /**
44
- * The constructor initializes a linked list with the given arguments as nodes.
45
- * @param {NodeVal[]} args - args is a rest parameter that allows the constructor to accept an arbitrary number of
46
- * arguments of type NodeVal.
47
- */
48
- constructor(...args: NodeVal[]);
49
- protected _head: SinglyLinkedListNode<NodeVal> | null;
50
- get head(): SinglyLinkedListNode<NodeVal> | null;
51
- set head(value: SinglyLinkedListNode<NodeVal> | null);
52
- protected _tail: SinglyLinkedListNode<NodeVal> | null;
53
- get tail(): SinglyLinkedListNode<NodeVal> | null;
54
- set tail(value: SinglyLinkedListNode<NodeVal> | null);
55
- protected _size: number;
56
- get size(): number;
57
- set size(value: number);
58
- /**
59
- * The `from` function in TypeScript creates a new SinglyLinkedList instance from an iterable object.
60
- * @param iterable - The `iterable` parameter is an object that can be iterated over, such as an array or a string. It
61
- * contains a collection of elements of type `T`.
62
- * @returns The method is returning a new instance of the SinglyLinkedList class.
63
- */
64
- static from<T>(iterable: Iterable<T>): SinglyLinkedList<T>;
65
- /**
66
- * The `get` function returns the value of a node at a given index in a data structure.
67
- * @param {number} index - The index parameter is a number that represents the position of the node in the data
68
- * structure.
69
- * @returns The method is returning the value of the node at the specified index if the node exists, otherwise it
70
- * returns undefined.
71
- */
72
- get(index: number): NodeVal | undefined;
73
- /**
74
- * The function `getNode` returns the node at a given index in a singly linked list.
75
- * @param {number} index - The `index` parameter is a number that represents the position of the node we want to
76
- * retrieve from the linked list.
77
- * @returns a SinglyLinkedListNode<NodeVal> object or undefined.
78
- */
79
- getNode(index: number): SinglyLinkedListNode<NodeVal> | undefined;
80
- /**
81
- * The function `findNodeIndex` searches for a node in a singly linked list that satisfies a given condition and
82
- * returns its index and the node itself.
83
- * @param callbackFn - The callbackFn parameter is a function that takes three arguments: data, index, and list. It is
84
- * used to determine whether a node in the singly linked list matches a certain condition. The function should return a
85
- * boolean value indicating whether the condition is met for the given node.
86
- * @returns The function `findNodeIndex` returns an object with two properties: `node` and `index`. The `node` property
87
- * contains the node that matches the condition specified in the `callbackFn` function, and the `index` property
88
- * contains the index of that node in the linked list. If no node matches the condition, the function returns
89
- * `undefined`.
90
- */
91
- findNodeIndex(callbackFn: (data: NodeVal, index: number, list: SinglyLinkedList<NodeVal>) => boolean): ({
92
- node: SinglyLinkedListNode<NodeVal>;
93
- index: number;
94
- }) | undefined;
95
- /**
96
- * The findNode function searches for a node in a singly linked list based on a given callback function.
97
- * @param callbackFn - A callback function that takes three parameters: data, index, and list. It returns a boolean
98
- * value indicating whether the current node matches the desired criteria.
99
- * @returns The function `findNode` returns a `SinglyLinkedListNode<NodeVal>` if a node satisfying the condition
100
- * specified by the `callbackFn` is found in the linked list. If no such node is found, it returns `undefined`.
101
- */
102
- findNode(callbackFn: (data: NodeVal, index: number, list: SinglyLinkedList<NodeVal>) => boolean): SinglyLinkedListNode<NodeVal> | undefined;
22
+ export declare class SinglyLinkedList<T> {
103
23
  /**
104
- * The `find` function in TypeScript searches for a node in a singly linked list based on a given callback function and
105
- * returns the value of the found node.
106
- * @param callbackFn - A callback function that takes three parameters: data, index, and list. It returns a boolean
107
- * value indicating whether the condition is met for a particular node in the linked list.
108
- * @returns The method `find` returns the `NodeVal` value of the first node in the linked list that satisfies the
109
- * condition specified by the `callbackFn` function. If no node satisfies the condition, it returns `undefined`.
24
+ * The constructor initializes the linked list with an empty head, tail, and length.
110
25
  */
111
- find(callbackFn: (data: NodeVal, index: number, list: SinglyLinkedList<NodeVal>) => boolean): NodeVal | undefined;
26
+ constructor();
27
+ private _head;
28
+ get head(): SinglyLinkedListNode<T> | null;
29
+ set head(value: SinglyLinkedListNode<T> | null);
30
+ private _tail;
31
+ get tail(): SinglyLinkedListNode<T> | null;
32
+ set tail(value: SinglyLinkedListNode<T> | null);
33
+ private _length;
34
+ get length(): number;
35
+ protected set length(value: number);
112
36
  /**
113
- * The findIndex function returns the index of the first node in a singly linked list that satisfies a given condition,
114
- * or -1 if no such node is found.
115
- * @param callbackFn - A callback function that takes three parameters: data, index, and list. It returns a boolean
116
- * value indicating whether the condition is met for a particular node in the singly linked list.
117
- * @returns The method `findIndex` returns a number.
37
+ * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
38
+ * array.
39
+ * @param {T[]} data - The `data` parameter is an array of elements of type `T`.
40
+ * @returns The `fromArray` function returns a `SinglyLinkedList` object.
118
41
  */
119
- findIndex(callbackFn: (data: NodeVal, index: number, list: SinglyLinkedList<NodeVal>) => boolean): number;
120
- append(...args: NodeVal[]): SinglyLinkedList<NodeVal>;
42
+ static fromArray<T>(data: T[]): SinglyLinkedList<T>;
43
+ getLength(): number;
121
44
  /**
122
- * The push function appends multiple NodeVal objects to a data structure and returns the new size of the data
123
- * structure.
124
- * @param {NodeVal[]} args - args is a rest parameter of type NodeVal[]. It allows the function to accept any number
125
- * of arguments of type NodeVal.
126
- * @returns The size of the data structure after the nodes are appended.
45
+ * The `push` function adds a new node with the given data to the end of a singly linked list.
46
+ * @param {T} data - The "data" parameter represents the value that you want to add to the linked list. It can be of
47
+ * any type (T) as specified in the generic type declaration of the class or function.
127
48
  */
128
- push(...args: NodeVal[]): number;
49
+ push(data: T): void;
129
50
  /**
130
- * The `prepend` function adds new nodes to the beginning of a singly linked list.
131
- * @param {NodeVal[]} args - An array of NodeVal objects.
132
- * @returns The `prepend` method is returning the updated `SinglyLinkedList` object.
51
+ * The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
52
+ * pointers accordingly.
53
+ * @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
54
+ * the linked list is empty, it returns `null`.
133
55
  */
134
- prepend(...args: NodeVal[]): SinglyLinkedList<NodeVal>;
56
+ pop(): T | null;
135
57
  /**
136
- * The `insertAt` function inserts a value at a specified index in a singly linked list.
137
- * @param {number} index - The index parameter is a number that represents the position at which the new node should be
138
- * inserted in the linked list.
139
- * @param {NodeVal} val - The `val` parameter represents the value of the node that you want to insert into the linked
140
- * list.
141
- * @returns The method `insertAt` returns the updated `SinglyLinkedList` object.
58
+ * The `shift()` function removes and returns the value of the first node in a linked list.
59
+ * @returns The value of the node that is being removed from the beginning of the linked list.
142
60
  */
143
- insertAt(index: number, val: NodeVal): SinglyLinkedList<NodeVal>;
61
+ shift(): T | null;
144
62
  /**
145
- * The removeNode function removes a node from a singly linked list and updates the head, tail, and size properties
146
- * accordingly.
147
- * @param node - The `node` parameter is of type `SinglyLinkedListNode<NodeVal>`, which represents a node in a singly
63
+ * The unshift function adds a new node with the given value to the beginning of a singly linked list.
64
+ * @param {T} val - The parameter "val" represents the value of the new node that will be added to the beginning of the
148
65
  * linked list.
149
- * @returns the removed node.
150
- */
151
- removeNode(node: SinglyLinkedListNode<NodeVal>): SinglyLinkedListNode<NodeVal>;
152
- /**
153
- * The `removeAt` function removes a node at a specified index from a singly linked list.
154
- * @param {number} index - The index parameter is a number that represents the position of the node to be removed in
155
- * the singly linked list.
156
- * @returns The method `removeAt` returns a `SinglyLinkedListNode<NodeVal>` if the node at the specified index is
157
- * found and removed successfully. If the node is not found, it returns `undefined`.
158
- */
159
- removeAt(index: number): SinglyLinkedListNode<NodeVal> | undefined;
160
- /**
161
- * The `insertBefore` function inserts a new node with a given value before a specified reference node in a singly
162
- * linked list.
163
- * @param referenceNode - The referenceNode parameter is the node in the linked list before which the new node will be
164
- * inserted.
165
- * @param {NodeVal} val - The value of the new node that will be inserted before the reference node.
166
- * @returns The method is returning the updated SinglyLinkedList object.
167
- */
168
- insertBefore(referenceNode: SinglyLinkedListNode<NodeVal>, val: NodeVal): SinglyLinkedList<NodeVal>;
169
- /**
170
- * The `sort` function uses the quicksort algorithm to sort the elements of a singly linked list based on a provided
171
- * comparison function.
172
- * @param start - The `start` parameter is the starting node of the sublist that needs to be sorted.
173
- * @param end - The `end` parameter is a reference to the last node in the linked list. It is used as the pivot element
174
- * for the quicksort algorithm.
175
- * @returns The `sort` method is returning the sorted `SinglyLinkedList` object.
176
66
  */
177
- sort(compare: (a: NodeVal, b: NodeVal) => boolean): SinglyLinkedList<NodeVal>;
67
+ unshift(val: T): void;
178
68
  /**
179
- * The `insertAfter` function inserts a new node with a given value after a specified reference node in a singly linked
180
- * list.
181
- * @param referenceNode - The referenceNode parameter is the node after which the new node will be inserted.
182
- * @param {NodeVal} val - The value of the new node that will be inserted after the reference node.
183
- * @returns The `insertAfter` method is returning the updated `SinglyLinkedList` object.
69
+ * The function `getAt` returns the value at a specified index in a linked list, or null if the index is out of range.
70
+ * @param {number} index - The index parameter is a number that represents the position of the element we want to
71
+ * retrieve from the list.
72
+ * @returns The method `getAt(index: number): T | null` returns the value at the specified index in the linked list, or
73
+ * `null` if the index is out of bounds.
184
74
  */
185
- insertAfter(referenceNode: SinglyLinkedListNode<NodeVal>, val: NodeVal): SinglyLinkedList<NodeVal>;
75
+ getAt(index: number): T | null;
186
76
  /**
187
- * The `shift()` function removes and returns the first element from a linked list.
188
- * @returns The `shift()` method is returning a value of type `NodeVal` or `undefined`.
189
- */
190
- shift(): NodeVal | undefined;
191
- /**
192
- * The `pop()` function removes and returns the last element from a linked list.
193
- * @returns The `pop()` method is returning a value of type `NodeVal` or `undefined`.
194
- */
195
- pop(): NodeVal | undefined;
196
- /**
197
- * The merge function merges two singly linked lists by updating the next and prev pointers, as well as the head, tail,
198
- * and size properties.
199
- * @param list - The parameter "list" is a SinglyLinkedList object that contains nodes with data of type NodeVal.
200
- */
201
- merge(list: SinglyLinkedList<NodeVal>): void;
202
- /**
203
- * The clear() function resets the linked list by setting the head and tail to null and the size to 0.
204
- * @returns The "this" object is being returned.
77
+ * The function `getNodeAt` returns the node at a given index in a singly linked list.
78
+ * @param {number} index - The `index` parameter is a number that represents the position of the node we want to
79
+ * retrieve from the linked list. It indicates the zero-based index of the node we want to access.
80
+ * @returns The method `getNodeAt(index: number)` returns a `SinglyLinkedListNode<T>` object if the node at the
81
+ * specified index exists, or `null` if the index is out of bounds.
205
82
  */
206
- clear(): this;
83
+ getNodeAt(index: number): SinglyLinkedListNode<T> | null;
207
84
  /**
208
- * The `slice` function returns a new SinglyLinkedList containing a portion of the original list, starting from the
209
- * specified index and ending at the optional end index.
210
- * @param {number} start - The `start` parameter is a number that represents the index at which to start slicing the
211
- * linked list.
212
- * @param {number} [end] - The `end` parameter is an optional number that specifies the index at which to end the
213
- * slicing. If no value is provided for `end`, or if the provided value is less than the `start` index, the slicing
214
- * will continue until the end of the list.
215
- * @returns a new SinglyLinkedList containing the sliced elements from the original list.
85
+ * The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
86
+ * @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
87
+ * data structure. It is of type number.
88
+ * @returns The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of
89
+ * bounds.
216
90
  */
217
- slice(start: number, end?: number): SinglyLinkedList<NodeVal | {}>;
91
+ deleteAt(index: number): T | null;
92
+ delete(valueOrNode: T): boolean;
93
+ delete(valueOrNode: SinglyLinkedListNode<T>): boolean;
218
94
  /**
219
- * The reverse() function reverses the order of nodes in a singly linked list.
220
- * @returns The reverse() method is returning the reversed SinglyLinkedList.
95
+ * The `insertAt` function inserts a value at a specified index in a singly linked list.
96
+ * @param {number} index - The index parameter represents the position at which the new value should be inserted in the
97
+ * linked list. It is of type number.
98
+ * @param {T} val - The `val` parameter represents the value that you want to insert into the linked list at the
99
+ * specified index.
100
+ * @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
101
+ * if the index is out of bounds.
221
102
  */
222
- reverse(): SinglyLinkedList<NodeVal>;
103
+ insertAt(index: number, val: T): boolean;
223
104
  /**
224
- * The `forEach` function iterates over a singly linked list and applies a callback function to each node, either in
225
- * forward or reverse order.
226
- * @param callbackFn - A callback function that will be called for each element in the linked list. It takes three
227
- * parameters:
228
- * @param [reverse=false] - A boolean value indicating whether to iterate over the linked list in reverse order. If set
229
- * to true, the iteration will start from the tail of the linked list and move towards the head. If set to false
230
- * (default), the iteration will start from the head and move towards the tail.
105
+ * The function checks if the length of a data structure is equal to zero and returns a boolean value indicating
106
+ * whether it is empty or not.
107
+ * @returns A boolean value indicating whether the length of the object is equal to 0.
231
108
  */
232
- forEach(callbackFn: (data: any, index: number, list: SinglyLinkedList<NodeVal>) => any, reverse?: boolean): void;
109
+ isEmpty(): boolean;
233
110
  /**
234
- * The map function takes a callback function and applies it to each element in the linked list, returning a new linked
235
- * list with the results.
236
- * @param callbackFn - A callback function that will be applied to each element in the linked list. It takes three
237
- * parameters:
238
- * @param [reverse=false] - The `reverse` parameter is a boolean value that determines whether the mapping should be
239
- * done in reverse order or not. If `reverse` is set to `true`, the mapping will be done in reverse order. If `reverse`
240
- * is set to `false` or not provided, the mapping will be
241
- * @returns The `map` function is returning a new `SinglyLinkedList` object.
111
+ * The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively.
242
112
  */
243
- map(callbackFn: (data: any, index: number, list: SinglyLinkedList<NodeVal>) => any, reverse?: boolean): SinglyLinkedList<NodeVal | {}>;
113
+ clear(): void;
244
114
  /**
245
- * The `filter` function filters the elements of a singly linked list based on a given callback function.
246
- * @param callbackFn - A callback function that takes three parameters: data, index, and list. It should return a
247
- * boolean value indicating whether the current element should be included in the filtered list or not.
248
- * @param [reverse=false] - The `reverse` parameter is a boolean value that determines whether the filtered list should
249
- * be reversed or not. If `reverse` is set to `true`, the filtered list will be in reverse order. If `reverse` is set
250
- * to `false` or not provided, the filtered list will be in
251
- * @returns The `filter` method is returning a new `SinglyLinkedList` object.
115
+ * The `toArray` function converts a linked list into an array.
116
+ * @returns The `toArray()` method is returning an array of type `T[]`.
252
117
  */
253
- filter(callbackFn: (data: NodeVal, index: number, list: SinglyLinkedList<NodeVal>) => boolean, reverse?: boolean): SinglyLinkedList<NodeVal | {}>;
118
+ toArray(): T[];
254
119
  /**
255
- * The `reduce` function iterates over a singly linked list and applies a callback function to each element,
256
- * accumulating a single value.
257
- * @param callbackFn - A callback function that will be called for each element in the linked list. It takes four
258
- * parameters:
259
- * @param {any} [start] - The `start` parameter is an optional initial value for the accumulator. If provided, the
260
- * `reduce` function will start accumulating from this value. If not provided, the `reduce` function will use the value
261
- * of the first element in the linked list as the initial value.
262
- * @param [reverse=false] - A boolean value indicating whether to iterate over the linked list in reverse order. If set
263
- * to true, the iteration will start from the tail of the linked list and move towards the head. If set to false
264
- * (default), the iteration will start from the head and move towards the tail.
265
- * @returns The `reduce` method returns the accumulated value after applying the callback function to each element in
266
- * the linked list.
120
+ * The `reverse` function reverses the order of the nodes in a singly linked list.
121
+ * @returns The reverse() method does not return anything. It has a return type of void.
267
122
  */
268
- reduce(callbackFn: (accumulator: any, currentNode: NodeVal, index: number, list: SinglyLinkedList<NodeVal>) => any, start?: any, reverse?: boolean): any;
123
+ reverse(): void;
269
124
  /**
270
- * The toArray() function converts a NodeVal object into an array of NodeVal objects.
271
- * @returns An array of NodeVal objects.
125
+ * The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
126
+ * @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This
127
+ * function is used to determine whether a particular value in the linked list satisfies a certain condition.
128
+ * @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
129
+ * the callback function. If no element satisfies the condition, it returns `null`.
272
130
  */
273
- toArray(): NodeVal[];
131
+ find(callback: (val: T) => boolean): T | null;
274
132
  /**
275
- * The `toString` function takes an optional separator and returns a string representation of an array, with each
276
- * element separated by the specified separator.
277
- * @param [separator= ] - The separator parameter is a string that specifies the character(s) to be used as a separator
278
- * between each element in the array when converting it to a string. By default, the separator is set to a space
279
- * character (' ').
280
- * @returns The toString method is being returned as a string.
133
+ * The `indexOf` function returns the index of the first occurrence of a given value in a linked list.
134
+ * @param {T} value - The value parameter is the value that you want to find the index of in the linked list.
135
+ * @returns The method is returning the index of the first occurrence of the specified value in the linked list. If the
136
+ * value is not found, it returns -1.
281
137
  */
282
- toString(separator?: string): string;
138
+ indexOf(value: T): number;
283
139
  /**
284
- * The function is an iterator that returns the values of each node in a linked list.
140
+ * The function finds a node in a singly linked list by its value and returns the node if found, otherwise returns
141
+ * null.
142
+ * @param {T} value - The value parameter is the value that we want to search for in the linked list.
143
+ * @returns a `SinglyLinkedListNode<T>` if a node with the specified value is found in the linked list. If no node with
144
+ * the specified value is found, the function returns `null`.
285
145
  */
286
- [Symbol.iterator](): IterableIterator<NodeVal>;
146
+ findNode(value: T): SinglyLinkedListNode<T> | null;
147
+ insertBefore(existingValue: T, newValue: T): boolean;
148
+ insertBefore(existingValue: SinglyLinkedListNode<T>, newValue: T): boolean;
149
+ insertAfter(existingValueOrNode: T, newValue: T): boolean;
150
+ insertAfter(existingValueOrNode: SinglyLinkedListNode<T>, newValue: T): boolean;
287
151
  /**
288
- * The function removes a node from either end of a singly linked list and returns its value.
289
- * @param {SinglyLinkedListNode<NodeVal> | null} node - The `node` parameter is a reference to a node in a singly
290
- * linked list. It can be either a `SinglyLinkedListNode` object or `null`.
291
- * @returns The value of the removed node if the node is not null, otherwise undefined.
152
+ * The function counts the number of occurrences of a given value in a linked list.
153
+ * @param {T} value - The value parameter is the value that you want to count the occurrences of in the linked list.
154
+ * @returns The count of occurrences of the given value in the linked list.
292
155
  */
293
- protected removeFromAnyEnd(node: SinglyLinkedListNode<NodeVal> | null): NodeVal | undefined;
156
+ countOccurrences(value: T): number;
294
157
  }