data-structure-typed 1.15.2 → 1.17.0

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 (212) hide show
  1. package/README.md +24 -24
  2. package/dist/data-structures/heap/heap.d.ts +30 -15
  3. package/dist/data-structures/heap/heap.js +60 -15
  4. package/dist/data-structures/heap/max-heap.d.ts +3 -3
  5. package/dist/data-structures/heap/min-heap.d.ts +3 -3
  6. package/dist/data-structures/index.d.ts +1 -0
  7. package/dist/data-structures/index.js +1 -0
  8. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +195 -68
  9. package/dist/data-structures/linked-list/doubly-linked-list.js +456 -244
  10. package/dist/data-structures/linked-list/singly-linked-list.d.ts +126 -241
  11. package/dist/data-structures/linked-list/singly-linked-list.js +331 -628
  12. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +4 -5
  13. package/dist/data-structures/priority-queue/max-priority-queue.js +30 -6
  14. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +4 -5
  15. package/dist/data-structures/priority-queue/min-priority-queue.js +31 -6
  16. package/dist/data-structures/priority-queue/priority-queue.d.ts +13 -2
  17. package/dist/data-structures/priority-queue/priority-queue.js +28 -22
  18. package/dist/data-structures/tree/index.d.ts +1 -0
  19. package/dist/data-structures/tree/index.js +17 -0
  20. package/dist/data-structures/tree/tree.d.ts +9 -0
  21. package/dist/data-structures/tree/tree.js +52 -0
  22. package/dist/data-structures/types/binary-tree.d.ts +0 -5
  23. package/dist/data-structures/types/heap.d.ts +0 -4
  24. package/dist/utils/types/utils.d.ts +1 -0
  25. package/docs/.nojekyll +1 -0
  26. package/docs/assets/highlight.css +92 -0
  27. package/docs/assets/main.js +58 -0
  28. package/docs/assets/search.js +1 -0
  29. package/docs/assets/style.css +1367 -0
  30. package/docs/classes/AVLTree.html +2191 -0
  31. package/docs/classes/AVLTreeNode.html +573 -0
  32. package/docs/classes/AaTree.html +149 -0
  33. package/docs/classes/AbstractEdge.html +268 -0
  34. package/docs/classes/AbstractGraph.html +926 -0
  35. package/docs/classes/AbstractVertex.html +214 -0
  36. package/docs/classes/ArrayDeque.html +416 -0
  37. package/docs/classes/BST.html +2037 -0
  38. package/docs/classes/BSTNode.html +569 -0
  39. package/docs/classes/BTree.html +149 -0
  40. package/docs/classes/BinaryIndexedTree.html +288 -0
  41. package/docs/classes/BinaryTree.html +1826 -0
  42. package/docs/classes/BinaryTreeNode.html +532 -0
  43. package/docs/classes/Character.html +197 -0
  44. package/docs/classes/CoordinateMap.html +468 -0
  45. package/docs/classes/CoordinateSet.html +429 -0
  46. package/docs/classes/Deque.html +897 -0
  47. package/docs/classes/DirectedEdge.html +353 -0
  48. package/docs/classes/DirectedGraph.html +1242 -0
  49. package/docs/classes/DirectedVertex.html +225 -0
  50. package/docs/classes/DoublyLinkedList.html +891 -0
  51. package/docs/classes/DoublyLinkedListNode.html +274 -0
  52. package/docs/classes/Heap.html +481 -0
  53. package/docs/classes/HeapItem.html +232 -0
  54. package/docs/classes/Matrix2D.html +479 -0
  55. package/docs/classes/MatrixNTI2D.html +217 -0
  56. package/docs/classes/MaxHeap.html +499 -0
  57. package/docs/classes/MaxPriorityQueue.html +808 -0
  58. package/docs/classes/MinHeap.html +500 -0
  59. package/docs/classes/MinPriorityQueue.html +810 -0
  60. package/docs/classes/Navigator.html +290 -0
  61. package/docs/classes/ObjectDeque.html +422 -0
  62. package/docs/classes/PriorityQueue.html +732 -0
  63. package/docs/classes/Queue.html +369 -0
  64. package/docs/classes/RBTree.html +149 -0
  65. package/docs/classes/SegmentTree.html +344 -0
  66. package/docs/classes/SegmentTreeNode.html +417 -0
  67. package/docs/classes/SinglyLinkedList.html +718 -0
  68. package/docs/classes/SinglyLinkedListNode.html +247 -0
  69. package/docs/classes/SplayTree.html +149 -0
  70. package/docs/classes/Stack.html +345 -0
  71. package/docs/classes/TreeMultiSet.html +2035 -0
  72. package/docs/classes/TreeNode.html +235 -0
  73. package/docs/classes/Trie.html +349 -0
  74. package/docs/classes/TrieNode.html +257 -0
  75. package/docs/classes/TwoThreeTree.html +149 -0
  76. package/docs/classes/UndirectedEdge.html +312 -0
  77. package/docs/classes/UndirectedGraph.html +1079 -0
  78. package/docs/classes/UndirectedVertex.html +225 -0
  79. package/docs/classes/Vector2D.html +782 -0
  80. package/docs/enums/CP.html +158 -0
  81. package/docs/enums/FamilyPosition.html +158 -0
  82. package/docs/enums/LoopType.html +159 -0
  83. package/docs/index.html +493 -0
  84. package/docs/interfaces/AVLTreeDeleted.html +160 -0
  85. package/docs/interfaces/HeapOptions.html +166 -0
  86. package/docs/interfaces/IDirectedGraph.html +242 -0
  87. package/docs/interfaces/IGraph.html +426 -0
  88. package/docs/interfaces/NavigatorParams.html +196 -0
  89. package/docs/interfaces/PriorityQueueOptions.html +167 -0
  90. package/docs/modules.html +216 -0
  91. package/docs/types/BSTComparator.html +139 -0
  92. package/docs/types/BSTDeletedResult.html +136 -0
  93. package/docs/types/BinaryTreeDeleted.html +136 -0
  94. package/docs/types/BinaryTreeNodeId.html +124 -0
  95. package/docs/types/BinaryTreeNodePropertyName.html +124 -0
  96. package/docs/types/DFSOrderPattern.html +124 -0
  97. package/docs/types/DijkstraResult.html +144 -0
  98. package/docs/types/Direction.html +124 -0
  99. package/docs/types/DoublyLinkedListGetBy.html +124 -0
  100. package/docs/types/NodeOrPropertyName.html +124 -0
  101. package/docs/types/PriorityQueueComparator.html +144 -0
  102. package/docs/types/PriorityQueueDFSOrderPattern.html +124 -0
  103. package/docs/types/ResultByProperty.html +129 -0
  104. package/docs/types/ResultsByProperty.html +129 -0
  105. package/docs/types/SegmentTreeNodeVal.html +124 -0
  106. package/docs/types/SpecifyOptional.html +131 -0
  107. package/docs/types/Thunk.html +132 -0
  108. package/docs/types/ToThunkFn.html +132 -0
  109. package/docs/types/TopologicalStatus.html +124 -0
  110. package/docs/types/TreeMultiSetDeletedResult.html +136 -0
  111. package/docs/types/TrlAsyncFn.html +137 -0
  112. package/docs/types/TrlFn.html +137 -0
  113. package/docs/types/Turning.html +124 -0
  114. package/docs/types/VertexId.html +124 -0
  115. package/{tests/unit/data-structures/binary-tree → notes}/bst.test.ts +37 -50
  116. package/notes/note.md +23 -0
  117. package/package.json +1 -3
  118. package/.idea/data-structure-typed.iml +0 -14
  119. package/.idea/modules.xml +0 -8
  120. package/.idea/vcs.xml +0 -6
  121. package/src/assets/complexities-diff.jpg +0 -0
  122. package/src/assets/data-structure-complexities.jpg +0 -0
  123. package/src/assets/logo.png +0 -0
  124. package/src/assets/overview-diagram-of-data-structures.png +0 -0
  125. package/src/data-structures/binary-tree/aa-tree.ts +0 -3
  126. package/src/data-structures/binary-tree/avl-tree.ts +0 -293
  127. package/src/data-structures/binary-tree/b-tree.ts +0 -3
  128. package/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -69
  129. package/src/data-structures/binary-tree/binary-tree.ts +0 -1492
  130. package/src/data-structures/binary-tree/bst.ts +0 -497
  131. package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  132. package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  133. package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  134. package/src/data-structures/binary-tree/index.ts +0 -11
  135. package/src/data-structures/binary-tree/rb-tree.ts +0 -3
  136. package/src/data-structures/binary-tree/segment-tree.ts +0 -267
  137. package/src/data-structures/binary-tree/splay-tree.ts +0 -3
  138. package/src/data-structures/binary-tree/tree-multiset.ts +0 -53
  139. package/src/data-structures/binary-tree/two-three-tree.ts +0 -3
  140. package/src/data-structures/diagrams/README.md +0 -5
  141. package/src/data-structures/graph/abstract-graph.ts +0 -958
  142. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  143. package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  144. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  145. package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  146. package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  147. package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  148. package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  149. package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  150. package/src/data-structures/graph/diagrams/mst.jpg +0 -0
  151. package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  152. package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  153. package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  154. package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  155. package/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  156. package/src/data-structures/graph/directed-graph.ts +0 -429
  157. package/src/data-structures/graph/index.ts +0 -3
  158. package/src/data-structures/graph/undirected-graph.ts +0 -259
  159. package/src/data-structures/hash/coordinate-map.ts +0 -74
  160. package/src/data-structures/hash/coordinate-set.ts +0 -63
  161. package/src/data-structures/hash/hash-table.ts +0 -1
  162. package/src/data-structures/hash/index.ts +0 -6
  163. package/src/data-structures/hash/pair.ts +0 -1
  164. package/src/data-structures/hash/tree-map.ts +0 -1
  165. package/src/data-structures/hash/tree-set.ts +0 -1
  166. package/src/data-structures/heap/heap.ts +0 -162
  167. package/src/data-structures/heap/index.ts +0 -3
  168. package/src/data-structures/heap/max-heap.ts +0 -31
  169. package/src/data-structures/heap/min-heap.ts +0 -34
  170. package/src/data-structures/index.ts +0 -13
  171. package/src/data-structures/linked-list/doubly-linked-list.ts +0 -365
  172. package/src/data-structures/linked-list/index.ts +0 -2
  173. package/src/data-structures/linked-list/singly-linked-list.ts +0 -757
  174. package/src/data-structures/linked-list/skip-linked-list.ts +0 -1
  175. package/src/data-structures/matrix/index.ts +0 -4
  176. package/src/data-structures/matrix/matrix.ts +0 -27
  177. package/src/data-structures/matrix/matrix2d.ts +0 -208
  178. package/src/data-structures/matrix/navigator.ts +0 -122
  179. package/src/data-structures/matrix/vector2d.ts +0 -316
  180. package/src/data-structures/priority-queue/index.ts +0 -3
  181. package/src/data-structures/priority-queue/max-priority-queue.ts +0 -24
  182. package/src/data-structures/priority-queue/min-priority-queue.ts +0 -24
  183. package/src/data-structures/priority-queue/priority-queue.ts +0 -349
  184. package/src/data-structures/queue/deque.ts +0 -251
  185. package/src/data-structures/queue/index.ts +0 -2
  186. package/src/data-structures/queue/queue.ts +0 -120
  187. package/src/data-structures/stack/index.ts +0 -1
  188. package/src/data-structures/stack/stack.ts +0 -98
  189. package/src/data-structures/trie/index.ts +0 -1
  190. package/src/data-structures/trie/trie.ts +0 -225
  191. package/src/data-structures/types/abstract-graph.ts +0 -51
  192. package/src/data-structures/types/avl-tree.ts +0 -6
  193. package/src/data-structures/types/binary-tree.ts +0 -15
  194. package/src/data-structures/types/bst.ts +0 -5
  195. package/src/data-structures/types/directed-graph.ts +0 -18
  196. package/src/data-structures/types/doubly-linked-list.ts +0 -1
  197. package/src/data-structures/types/heap.ts +0 -8
  198. package/src/data-structures/types/index.ts +0 -13
  199. package/src/data-structures/types/navigator.ts +0 -13
  200. package/src/data-structures/types/priority-queue.ts +0 -9
  201. package/src/data-structures/types/segment-tree.ts +0 -1
  202. package/src/data-structures/types/singly-linked-list.ts +0 -1
  203. package/src/data-structures/types/tree-multiset.ts +0 -3
  204. package/src/index.ts +0 -1
  205. package/src/utils/index.ts +0 -2
  206. package/src/utils/types/index.ts +0 -1
  207. package/src/utils/types/utils.ts +0 -4
  208. package/src/utils/utils.ts +0 -78
  209. package/tests/unit/data-structures/graph/abstract-graph.ts +0 -0
  210. package/tests/unit/data-structures/graph/directed-graph.test.ts +0 -492
  211. package/tests/unit/data-structures/graph/index.ts +0 -3
  212. package/tests/unit/data-structures/graph/undirected-graph.ts +0 -0
@@ -5,290 +5,175 @@
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;
22
+ export declare class SinglyLinkedList<T> {
80
23
  /**
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`.
24
+ * The constructor initializes the linked list with an empty head, tail, and length.
90
25
  */
91
- findNodeIndex(callbackFn: (data: NodeVal, index: number, list: SinglyLinkedList<NodeVal>) => boolean): ({
92
- node: SinglyLinkedListNode<NodeVal>;
93
- index: number;
94
- }) | 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);
95
36
  /**
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`.
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.
101
41
  */
102
- findNode(callbackFn: (data: NodeVal, index: number, list: SinglyLinkedList<NodeVal>) => boolean): SinglyLinkedListNode<NodeVal> | undefined;
42
+ static fromArray<T>(data: T[]): SinglyLinkedList<T>;
43
+ getLength(): number;
103
44
  /**
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`.
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.
110
48
  */
111
- find(callbackFn: (data: NodeVal, index: number, list: SinglyLinkedList<NodeVal>) => boolean): NodeVal | undefined;
49
+ push(data: T): void;
112
50
  /**
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.
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`.
118
55
  */
119
- findIndex(callbackFn: (data: NodeVal, index: number, list: SinglyLinkedList<NodeVal>) => boolean): number;
120
- append(...args: NodeVal[]): SinglyLinkedList<NodeVal>;
56
+ pop(): T | null;
121
57
  /**
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.
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.
127
60
  */
128
- push(...args: NodeVal[]): number;
61
+ shift(): T | null;
129
62
  /**
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.
133
- */
134
- prepend(...args: NodeVal[]): SinglyLinkedList<NodeVal>;
135
- /**
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.
142
- */
143
- insertAt(index: number, val: NodeVal): SinglyLinkedList<NodeVal>;
144
- /**
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
66
  */
151
- removeNode(node: SinglyLinkedListNode<NodeVal>): SinglyLinkedListNode<NodeVal>;
67
+ unshift(val: T): void;
152
68
  /**
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`.
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.
158
74
  */
159
- removeAt(index: number): SinglyLinkedListNode<NodeVal> | undefined;
75
+ getAt(index: number): T | null;
160
76
  /**
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.
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.
167
82
  */
168
- insertBefore(referenceNode: SinglyLinkedListNode<NodeVal>, val: NodeVal): SinglyLinkedList<NodeVal>;
83
+ getNodeAt(index: number): SinglyLinkedListNode<T> | null;
169
84
  /**
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.
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.
176
90
  */
177
- sort(compare: (a: NodeVal, b: NodeVal) => boolean): SinglyLinkedList<NodeVal>;
91
+ deleteAt(index: number): T | null;
178
92
  /**
179
- * The `insertAfter` function inserts a new node with a given value after a specified reference node in a singly linked
93
+ * The `delete` function removes a specified value from a linked list and returns true if the value was found and
94
+ * removed, otherwise it returns false.
95
+ * @param {T} value - The value parameter represents the value of the node that needs to be deleted from the linked
180
96
  * 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.
97
+ * @returns The `delete` method returns a boolean value. It returns `true` if the value was successfully deleted from
98
+ * the linked list, and `false` if the value was not found in the linked list.
184
99
  */
185
- insertAfter(referenceNode: SinglyLinkedListNode<NodeVal>, val: NodeVal): SinglyLinkedList<NodeVal>;
100
+ delete(value: T): boolean;
186
101
  /**
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`.
102
+ * The `insert` function inserts a value at a specified index in a singly linked list.
103
+ * @param {number} index - The index parameter represents the position at which the new value should be inserted in the
104
+ * linked list. It is of type number.
105
+ * @param {T} val - The `val` parameter represents the value that you want to insert into the linked list at the
106
+ * specified index.
107
+ * @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
108
+ * if the index is out of bounds.
189
109
  */
190
- shift(): NodeVal | undefined;
110
+ insert(index: number, val: T): boolean;
191
111
  /**
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.
205
- */
206
- clear(): this;
207
- /**
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.
112
+ * The function checks if the length of a data structure is equal to zero and returns a boolean value indicating
113
+ * whether it is empty or not.
114
+ * @returns A boolean value indicating whether the length of the object is equal to 0.
216
115
  */
217
- slice(start: number, end?: number): SinglyLinkedList<NodeVal | {}>;
116
+ isEmpty(): boolean;
218
117
  /**
219
- * The reverse() function reverses the order of nodes in a singly linked list.
220
- * @returns The reverse() method is returning the reversed SinglyLinkedList.
118
+ * The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively.
221
119
  */
222
- reverse(): SinglyLinkedList<NodeVal>;
120
+ clear(): void;
223
121
  /**
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.
122
+ * The `toArray` function converts a linked list into an array.
123
+ * @returns The `toArray()` method is returning an array of type `T[]`.
231
124
  */
232
- forEach(callbackFn: (data: any, index: number, list: SinglyLinkedList<NodeVal>) => any, reverse?: boolean): void;
125
+ toArray(): T[];
233
126
  /**
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.
127
+ * The `reverse` function reverses the order of the nodes in a singly linked list.
128
+ * @returns The reverse() method does not return anything. It has a return type of void.
242
129
  */
243
- map(callbackFn: (data: any, index: number, list: SinglyLinkedList<NodeVal>) => any, reverse?: boolean): SinglyLinkedList<NodeVal | {}>;
130
+ reverse(): void;
244
131
  /**
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.
132
+ * The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
133
+ * @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This
134
+ * function is used to determine whether a particular value in the linked list satisfies a certain condition.
135
+ * @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
136
+ * the callback function. If no element satisfies the condition, it returns `null`.
252
137
  */
253
- filter(callbackFn: (data: NodeVal, index: number, list: SinglyLinkedList<NodeVal>) => boolean, reverse?: boolean): SinglyLinkedList<NodeVal | {}>;
138
+ find(callback: (val: T) => boolean): T | null;
254
139
  /**
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.
140
+ * The `indexOf` function returns the index of the first occurrence of a given value in a linked list.
141
+ * @param {T} value - The value parameter is the value that you want to find the index of in the linked list.
142
+ * @returns The method is returning the index of the first occurrence of the specified value in the linked list. If the
143
+ * value is not found, it returns -1.
267
144
  */
268
- reduce(callbackFn: (accumulator: any, currentNode: NodeVal, index: number, list: SinglyLinkedList<NodeVal>) => any, start?: any, reverse?: boolean): any;
145
+ indexOf(value: T): number;
269
146
  /**
270
- * The toArray() function converts a NodeVal object into an array of NodeVal objects.
271
- * @returns An array of NodeVal objects.
147
+ * The function finds a node in a singly linked list by its value and returns the node if found, otherwise returns
148
+ * null.
149
+ * @param {T} value - The value parameter is the value that we want to search for in the linked list.
150
+ * @returns a `SinglyLinkedListNode<T>` if a node with the specified value is found in the linked list. If no node with
151
+ * the specified value is found, the function returns `null`.
272
152
  */
273
- toArray(): NodeVal[];
153
+ findNode(value: T): SinglyLinkedListNode<T> | null;
274
154
  /**
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.
155
+ * The `insertBefore` function inserts a new value before an existing value in a singly linked list.
156
+ * @param {T} existingValue - The existing value is the value that already exists in the linked list and before which
157
+ * we want to insert a new value.
158
+ * @param {T} newValue - The `newValue` parameter represents the value that you want to insert into the linked list.
159
+ * @returns The `insertBefore` function returns a boolean value. It returns `true` if the `newValue` is successfully
160
+ * inserted before the first occurrence of `existingValue` in the linked list. It returns `false` if the
161
+ * `existingValue` is not found in the linked list.
281
162
  */
282
- toString(separator?: string): string;
163
+ insertBefore(existingValue: T, newValue: T): boolean;
283
164
  /**
284
- * The function is an iterator that returns the values of each node in a linked list.
165
+ * The function inserts a new value after an existing value in a singly linked list.
166
+ * @param {T} existingValue - The existing value is the value of the node after which we want to insert the new value.
167
+ * @param {T} newValue - The `newValue` parameter represents the value that you want to insert into the linked list
168
+ * after the node with the `existingValue`.
169
+ * @returns The method is returning a boolean value. It returns true if the insertion is successful and false if the
170
+ * existing value is not found in the linked list.
285
171
  */
286
- [Symbol.iterator](): IterableIterator<NodeVal>;
172
+ insertAfter(existingValue: T, newValue: T): boolean;
287
173
  /**
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.
174
+ * The function counts the number of occurrences of a given value in a linked list.
175
+ * @param {T} value - The value parameter is the value that you want to count the occurrences of in the linked list.
176
+ * @returns The count of occurrences of the given value in the linked list.
292
177
  */
293
- protected removeFromAnyEnd(node: SinglyLinkedListNode<NodeVal> | null): NodeVal | undefined;
178
+ countOccurrences(value: T): number;
294
179
  }