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
@@ -1,9 +1,48 @@
1
1
  "use strict";
2
+ var __values = (this && this.__values) || function(o) {
3
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
+ if (m) return m.call(o);
5
+ if (o && typeof o.length === "number") return {
6
+ next: function () {
7
+ if (o && i >= o.length) o = void 0;
8
+ return { value: o && o[i++], done: !o };
9
+ }
10
+ };
11
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
+ };
13
+ var __read = (this && this.__read) || function (o, n) {
14
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
15
+ if (!m) return o;
16
+ var i = m.call(o), r, ar = [], e;
17
+ try {
18
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
+ }
20
+ catch (error) { e = { error: error }; }
21
+ finally {
22
+ try {
23
+ if (r && !r.done && (m = i["return"])) m.call(i);
24
+ }
25
+ finally { if (e) throw e.error; }
26
+ }
27
+ return ar;
28
+ };
2
29
  Object.defineProperty(exports, "__esModule", { value: true });
3
30
  exports.DoublyLinkedList = exports.DoublyLinkedListNode = void 0;
31
+ /**
32
+ * data-structure-typed
33
+ *
34
+ * @author Tyler Zeng
35
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
36
+ * @license MIT License
37
+ */
4
38
  var DoublyLinkedListNode = /** @class */ (function () {
5
- function DoublyLinkedListNode(nodeValue) {
6
- this._val = nodeValue;
39
+ /**
40
+ * The constructor function initializes the value, next, and previous properties of an object.
41
+ * @param {T} val - The "val" parameter is the value that will be stored in the node. It can be of any data type, as it
42
+ * is defined as a generic type "T".
43
+ */
44
+ function DoublyLinkedListNode(val) {
45
+ this._val = val;
7
46
  this._next = null;
8
47
  this._prev = null;
9
48
  }
@@ -11,8 +50,8 @@ var DoublyLinkedListNode = /** @class */ (function () {
11
50
  get: function () {
12
51
  return this._val;
13
52
  },
14
- set: function (v) {
15
- this._val = v;
53
+ set: function (value) {
54
+ this._val = value;
16
55
  },
17
56
  enumerable: false,
18
57
  configurable: true
@@ -21,8 +60,8 @@ var DoublyLinkedListNode = /** @class */ (function () {
21
60
  get: function () {
22
61
  return this._next;
23
62
  },
24
- set: function (v) {
25
- this._next = v;
63
+ set: function (value) {
64
+ this._next = value;
26
65
  },
27
66
  enumerable: false,
28
67
  configurable: true
@@ -31,8 +70,8 @@ var DoublyLinkedListNode = /** @class */ (function () {
31
70
  get: function () {
32
71
  return this._prev;
33
72
  },
34
- set: function (v) {
35
- this._prev = v;
73
+ set: function (value) {
74
+ this._prev = value;
36
75
  },
37
76
  enumerable: false,
38
77
  configurable: true
@@ -41,325 +80,498 @@ var DoublyLinkedListNode = /** @class */ (function () {
41
80
  }());
42
81
  exports.DoublyLinkedListNode = DoublyLinkedListNode;
43
82
  var DoublyLinkedList = /** @class */ (function () {
83
+ /**
84
+ * The constructor initializes the linked list with an empty head, tail, and length.
85
+ */
44
86
  function DoublyLinkedList() {
45
- this._first = null;
46
- this._last = null;
47
- this._size = 0;
87
+ this._head = null;
88
+ this._tail = null;
89
+ this._length = 0;
48
90
  }
49
- Object.defineProperty(DoublyLinkedList.prototype, "first", {
91
+ Object.defineProperty(DoublyLinkedList.prototype, "head", {
50
92
  get: function () {
51
- return this._first;
93
+ return this._head;
52
94
  },
53
- set: function (v) {
54
- this._first = v;
95
+ set: function (value) {
96
+ this._head = value;
55
97
  },
56
98
  enumerable: false,
57
99
  configurable: true
58
100
  });
59
- Object.defineProperty(DoublyLinkedList.prototype, "last", {
101
+ Object.defineProperty(DoublyLinkedList.prototype, "tail", {
60
102
  get: function () {
61
- return this._last;
103
+ return this._tail;
62
104
  },
63
- set: function (v) {
64
- this._last = v;
105
+ set: function (value) {
106
+ this._tail = value;
65
107
  },
66
108
  enumerable: false,
67
109
  configurable: true
68
110
  });
69
- Object.defineProperty(DoublyLinkedList.prototype, "size", {
111
+ Object.defineProperty(DoublyLinkedList.prototype, "length", {
70
112
  get: function () {
71
- return this._size;
113
+ return this._length;
72
114
  },
73
- set: function (v) {
74
- this._size = v;
115
+ set: function (value) {
116
+ this._length = value;
75
117
  },
76
118
  enumerable: false,
77
119
  configurable: true
78
120
  });
79
121
  /**
80
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
122
+ * The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
123
+ * given array.
124
+ * @param {T[]} data - The `data` parameter is an array of elements of type `T`.
125
+ * @returns The `fromArray` function returns a DoublyLinkedList object.
81
126
  */
82
- DoublyLinkedList.prototype.getFirst = function () {
83
- return this._first;
127
+ DoublyLinkedList.fromArray = function (data) {
128
+ var e_1, _a;
129
+ var doublyLinkedList = new DoublyLinkedList();
130
+ try {
131
+ for (var data_1 = __values(data), data_1_1 = data_1.next(); !data_1_1.done; data_1_1 = data_1.next()) {
132
+ var item = data_1_1.value;
133
+ doublyLinkedList.push(item);
134
+ }
135
+ }
136
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
137
+ finally {
138
+ try {
139
+ if (data_1_1 && !data_1_1.done && (_a = data_1.return)) _a.call(data_1);
140
+ }
141
+ finally { if (e_1) throw e_1.error; }
142
+ }
143
+ return doublyLinkedList;
144
+ };
145
+ DoublyLinkedList.prototype.getLength = function () {
146
+ return this._length;
84
147
  };
85
148
  /**
86
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
149
+ * The push function adds a new node with the given value to the end of the doubly linked list.
150
+ * @param {T} val - The value to be added to the linked list.
87
151
  */
88
- DoublyLinkedList.prototype.getLast = function () {
89
- return this._last;
152
+ DoublyLinkedList.prototype.push = function (val) {
153
+ var newNode = new DoublyLinkedListNode(val);
154
+ if (!this.head) {
155
+ this.head = newNode;
156
+ this.tail = newNode;
157
+ }
158
+ else {
159
+ newNode.prev = this.tail;
160
+ this.tail.next = newNode;
161
+ this.tail = newNode;
162
+ }
163
+ this.length++;
90
164
  };
91
165
  /**
92
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
166
+ * The `pop()` function removes and returns the value of the last node in a doubly linked list.
167
+ * @returns The method is returning the value of the removed node (removedNode.val) if the list is not empty. If the
168
+ * list is empty, it returns null.
93
169
  */
94
- DoublyLinkedList.prototype.getSize = function () {
95
- return this._size;
170
+ DoublyLinkedList.prototype.pop = function () {
171
+ if (!this.tail)
172
+ return null;
173
+ var removedNode = this.tail;
174
+ if (this.head === this.tail) {
175
+ this.head = null;
176
+ this.tail = null;
177
+ }
178
+ else {
179
+ this.tail = removedNode.prev;
180
+ this.tail.next = null;
181
+ }
182
+ this.length--;
183
+ return removedNode.val;
96
184
  };
97
185
  /**
98
- * The function adds a new node with a given value to the beginning of a doubly linked list.
99
- * @param {T} val - The `val` parameter represents the value of the element that you want to add to the beginning of
100
- * the doubly linked list.
101
- * @returns A boolean value is being returned.
186
+ * The `shift()` function removes and returns the value of the first node in a doubly linked list.
187
+ * @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
188
+ * list.
102
189
  */
103
- DoublyLinkedList.prototype.addFirst = function (val) {
104
- var newNode = new DoublyLinkedListNode(val);
105
- if (this._size === 0) {
106
- this._first = newNode;
107
- this._last = newNode;
190
+ DoublyLinkedList.prototype.shift = function () {
191
+ if (!this.head)
192
+ return null;
193
+ var removedNode = this.head;
194
+ if (this.head === this.tail) {
195
+ this.head = null;
196
+ this.tail = null;
108
197
  }
109
198
  else {
110
- if (this._first)
111
- this._first.prev = newNode;
112
- newNode.next = this._first;
113
- this._first = newNode;
199
+ this.head = removedNode.next;
200
+ this.head.prev = null;
114
201
  }
115
- this._size++;
116
- return true;
202
+ this.length--;
203
+ return removedNode.val;
117
204
  };
118
205
  /**
119
- * The function adds a new node with a given value to the end of a doubly linked list.
120
- * @param {T} val - The `val` parameter represents the value of the element that you want to add to the end of the
206
+ * The unshift function adds a new node with the given value to the beginning of a doubly linked list.
207
+ * @param {T} val - The `val` parameter represents the value of the new node that will be added to the beginning of the
121
208
  * doubly linked list.
122
- * @returns a boolean value, which is always true.
123
209
  */
124
- DoublyLinkedList.prototype.addLast = function (val) {
210
+ DoublyLinkedList.prototype.unshift = function (val) {
125
211
  var newNode = new DoublyLinkedListNode(val);
126
- if (this._size === 0) {
127
- this._first = newNode;
128
- this._last = newNode;
212
+ if (!this.head) {
213
+ this.head = newNode;
214
+ this.tail = newNode;
129
215
  }
130
216
  else {
131
- if (this._last)
132
- this._last.next = newNode;
133
- newNode.prev = this._last;
134
- this._last = newNode;
217
+ newNode.next = this.head;
218
+ this.head.prev = newNode;
219
+ this.head = newNode;
135
220
  }
136
- this._size++;
137
- return true;
221
+ this.length++;
138
222
  };
139
223
  /**
140
- * The `peekFirst` function returns the first node or value in a doubly linked list, depending on the specified
141
- * parameter.
142
- * @param {DoublyLinkedListGetBy} [by] - The "by" parameter is an optional parameter of type DoublyLinkedListGetBy. It
143
- * is used to specify whether to return the first node, the value of the first node, or the first node itself.
144
- * @returns The method `peekFirst` returns either the first node of the doubly linked list (`DoublyLinkedListNode<T>`),
145
- * the value of the first node (`T`), or `null` depending on the value of the `by` parameter.
224
+ * The `getAt` function returns the value at a specified index in a linked list, or null if the index is out of bounds.
225
+ * @param {number} index - The index parameter is a number that represents the position of the element we want to
226
+ * retrieve from the list.
227
+ * @returns The method is returning the value at the specified index in the linked list. If the index is out of bounds
228
+ * or the linked list is empty, it will return null.
146
229
  */
147
- DoublyLinkedList.prototype.peekFirst = function (by) {
148
- var _a, _b, _c, _d, _e;
149
- switch (by) {
150
- case 'node':
151
- return (_a = this._first) !== null && _a !== void 0 ? _a : null;
152
- case 'val':
153
- return (_c = (_b = this._first) === null || _b === void 0 ? void 0 : _b.val) !== null && _c !== void 0 ? _c : null;
154
- default:
155
- return (_e = (_d = this._first) === null || _d === void 0 ? void 0 : _d.val) !== null && _e !== void 0 ? _e : null;
230
+ DoublyLinkedList.prototype.getAt = function (index) {
231
+ if (index < 0 || index >= this.length)
232
+ return null;
233
+ var current = this.head;
234
+ for (var i = 0; i < index; i++) {
235
+ current = current.next;
156
236
  }
237
+ return current.val;
157
238
  };
158
239
  /**
159
- * The `peekLast` function returns the last node or value in a doubly linked list.
160
- * @param {DoublyLinkedListGetBy} [by=val] - The "by" parameter is an optional parameter of type DoublyLinkedListGetBy.
161
- * It specifies whether to return the last node, the value of the last node, or both. The default value is 'val', which
162
- * means that if no value is provided for the "by" parameter, the method
163
- * @returns The method `peekLast` returns the last node, value, or null based on the specified `by` parameter.
240
+ * The function `getNodeAt` returns the node at a given index in a doubly linked list, or null if the index is out of
241
+ * range.
242
+ * @param {number} index - The `index` parameter is a number that represents the position of the node we want to
243
+ * retrieve from the doubly linked list. It indicates the zero-based index of the node we want to access.
244
+ * @returns The method `getNodeAt(index: number)` returns a `DoublyLinkedListNode<T>` object if the index is within the
245
+ * valid range of the linked list, otherwise it returns `null`.
164
246
  */
165
- DoublyLinkedList.prototype.peekLast = function (by) {
166
- var _a, _b, _c, _d, _e;
167
- if (by === void 0) { by = 'val'; }
168
- switch (by) {
169
- case 'node':
170
- return (_a = this._last) !== null && _a !== void 0 ? _a : null;
171
- case 'val':
172
- return (_c = (_b = this._last) === null || _b === void 0 ? void 0 : _b.val) !== null && _c !== void 0 ? _c : null;
173
- default:
174
- return (_e = (_d = this._last) === null || _d === void 0 ? void 0 : _d.val) !== null && _e !== void 0 ? _e : null;
247
+ DoublyLinkedList.prototype.getNodeAt = function (index) {
248
+ if (index < 0 || index >= this.length)
249
+ return null;
250
+ var current = this.head;
251
+ for (var i = 0; i < index; i++) {
252
+ current = current.next;
175
253
  }
254
+ return current;
176
255
  };
177
256
  /**
178
- * The function `pollFirst` removes and returns the first element of a doubly linked list, either as a node or its
179
- * value, depending on the specified parameter.
180
- * @param {DoublyLinkedListGetBy} [by=val] - The "by" parameter is an optional parameter of type DoublyLinkedListGetBy.
181
- * It specifies the criteria by which the first element should be retrieved from the doubly linked list. The default
182
- * value is 'val', which means the first element will be retrieved by its value. Other possible values for "by
183
- * @returns The method `pollFirst` returns either the value of the first node in the doubly linked list, the first node
184
- * itself, or null if the list is empty. The specific return type depends on the value of the `by` parameter. If `by`
185
- * is set to 'node', the method returns the first node. If `by` is set to 'val', the method returns the value
257
+ * The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
258
+ * node if found, otherwise it returns null.
259
+ * @param {T} val - The `val` parameter is the value that we want to search for in the doubly linked list.
260
+ * @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<T>` if a node with the specified value `val`
261
+ * is found in the linked list. If no such node is found, it returns `null`.
186
262
  */
187
- DoublyLinkedList.prototype.pollFirst = function (by) {
188
- var _a, _b, _c;
189
- if (by === void 0) { by = 'val'; }
190
- if (this._size === 0)
191
- return null;
192
- var oldHead = this._first;
193
- if (this._size === 1) {
194
- this._first = null;
195
- this._last = null;
263
+ DoublyLinkedList.prototype.findNode = function (val) {
264
+ var current = this.head;
265
+ while (current) {
266
+ if (current.val === val) {
267
+ return current;
268
+ }
269
+ current = current.next;
196
270
  }
197
- else {
198
- this._first = (_a = oldHead === null || oldHead === void 0 ? void 0 : oldHead.next) !== null && _a !== void 0 ? _a : null;
199
- if (this._first)
200
- this._first.prev = null;
201
- if (oldHead)
202
- oldHead.next = null;
271
+ return null;
272
+ };
273
+ /**
274
+ * The `insert` function inserts a value at a specified index in a doubly linked list.
275
+ * @param {number} index - The index parameter represents the position at which the new value should be inserted in the
276
+ * DoublyLinkedList. It is of type number.
277
+ * @param {T} val - The `val` parameter represents the value that you want to insert into the Doubly Linked List at the
278
+ * specified index.
279
+ * @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
280
+ * if the index is out of bounds.
281
+ */
282
+ DoublyLinkedList.prototype.insert = function (index, val) {
283
+ if (index < 0 || index > this.length)
284
+ return false;
285
+ if (index === 0) {
286
+ this.unshift(val);
287
+ return true;
203
288
  }
204
- this._size--;
205
- switch (by) {
206
- case 'node':
207
- return oldHead !== null && oldHead !== void 0 ? oldHead : null;
208
- case 'val':
209
- return (_b = oldHead === null || oldHead === void 0 ? void 0 : oldHead.val) !== null && _b !== void 0 ? _b : null;
210
- default:
211
- return (_c = oldHead === null || oldHead === void 0 ? void 0 : oldHead.val) !== null && _c !== void 0 ? _c : null;
289
+ if (index === this.length) {
290
+ this.push(val);
291
+ return true;
212
292
  }
293
+ var newNode = new DoublyLinkedListNode(val);
294
+ var prevNode = this.getNodeAt(index - 1);
295
+ var nextNode = prevNode.next;
296
+ newNode.prev = prevNode;
297
+ newNode.next = nextNode;
298
+ prevNode.next = newNode;
299
+ nextNode.prev = newNode;
300
+ this.length++;
301
+ return true;
213
302
  };
214
303
  /**
215
- * The function `pollLast` removes and returns the last element in a doubly linked list, either as a node or its value,
216
- * depending on the specified parameter.
217
- * @param {DoublyLinkedListGetBy} [by=val] - The parameter "by" is of type DoublyLinkedListGetBy, which is an enum that
218
- * can have two possible values: 'node' or 'val'. It determines the type of value that will be returned by the pollLast
219
- * method. If 'node' is specified, the method will return the
220
- * @returns The method `pollLast` returns either a `DoublyLinkedListNode<T>`, the value of the node (`T`), or `null`.
221
- * The specific type that is returned depends on the value of the `by` parameter. If `by` is set to `'node'`, then a
222
- * `DoublyLinkedListNode<T>` is returned. If `by` is set to `'
304
+ * The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
305
+ * @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
306
+ * data structure. It is of type number.
307
+ * @returns The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of
308
+ * bounds.
223
309
  */
224
- DoublyLinkedList.prototype.pollLast = function (by) {
225
- var _a, _b, _c;
226
- if (by === void 0) { by = 'val'; }
227
- if (this._size === 0)
310
+ DoublyLinkedList.prototype.deleteAt = function (index) {
311
+ if (index < 0 || index >= this.length)
228
312
  return null;
229
- var polled = this._last;
230
- if (this._size === 1) {
231
- this._first = null;
232
- this._last = null;
313
+ if (index === 0)
314
+ return this.shift();
315
+ if (index === this.length - 1)
316
+ return this.pop();
317
+ var removedNode = this.getNodeAt(index);
318
+ var prevNode = removedNode.prev;
319
+ var nextNode = removedNode.next;
320
+ prevNode.next = nextNode;
321
+ nextNode.prev = prevNode;
322
+ this.length--;
323
+ return removedNode.val;
324
+ };
325
+ /**
326
+ * The `delete` function removes a node with a specific value from a doubly linked list.
327
+ * @param {T} val - The `val` parameter represents the value that you want to delete from the linked list.
328
+ * @returns The `delete` method returns a boolean value. It returns `true` if the value `val` is found and deleted from
329
+ * the linked list, and `false` if the value is not found in the linked list.
330
+ */
331
+ DoublyLinkedList.prototype.delete = function (val) {
332
+ var current = this.head;
333
+ while (current) {
334
+ if (current.val === val) {
335
+ if (current === this.head) {
336
+ this.shift();
337
+ }
338
+ else if (current === this.tail) {
339
+ this.pop();
340
+ }
341
+ else {
342
+ var prevNode = current.prev;
343
+ var nextNode = current.next;
344
+ prevNode.next = nextNode;
345
+ nextNode.prev = prevNode;
346
+ this.length--;
347
+ }
348
+ return true;
349
+ }
350
+ current = current.next;
233
351
  }
234
- else {
235
- this._last = (_a = polled === null || polled === void 0 ? void 0 : polled.prev) !== null && _a !== void 0 ? _a : null;
236
- if (this._last)
237
- this._last.next = null;
238
- if (polled)
239
- polled.prev = null;
352
+ return false;
353
+ };
354
+ /**
355
+ * The `toArray` function converts a linked list into an array.
356
+ * @returns The `toArray()` method is returning an array of type `T[]`.
357
+ */
358
+ DoublyLinkedList.prototype.toArray = function () {
359
+ var array = [];
360
+ var current = this.head;
361
+ while (current) {
362
+ array.push(current.val);
363
+ current = current.next;
240
364
  }
241
- this._size--;
242
- switch (by) {
243
- case 'node':
244
- return polled !== null && polled !== void 0 ? polled : null;
245
- case 'val':
246
- return (_b = polled === null || polled === void 0 ? void 0 : polled.val) !== null && _b !== void 0 ? _b : null;
247
- default:
248
- return (_c = polled === null || polled === void 0 ? void 0 : polled.val) !== null && _c !== void 0 ? _c : null;
365
+ return array;
366
+ };
367
+ /**
368
+ * The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively.
369
+ */
370
+ DoublyLinkedList.prototype.clear = function () {
371
+ this._head = null;
372
+ this._tail = null;
373
+ this._length = 0;
374
+ };
375
+ /**
376
+ * The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
377
+ * @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This
378
+ * function is used to determine whether a particular value in the linked list satisfies a certain condition.
379
+ * @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
380
+ * the callback function. If no element satisfies the condition, it returns `null`.
381
+ */
382
+ DoublyLinkedList.prototype.find = function (callback) {
383
+ var current = this.head;
384
+ while (current) {
385
+ if (callback(current.val)) {
386
+ return current.val;
387
+ }
388
+ current = current.next;
249
389
  }
390
+ return null;
250
391
  };
251
392
  /**
252
- * Returns the node at the specified index of the linked list.
253
- * If index = 0; first element in the list is returned.
254
- * If index = 3; fourth element in the list is returned.
255
- * @param index Index of the node to be retrieved
256
- * @param by Return value type
393
+ * The function returns the index of the first occurrence of a given value in a linked list.
394
+ * @param {T} val - The parameter `val` is of type `T`, which means it can be any data type. It represents the value
395
+ * that we are searching for in the linked list.
396
+ * @returns The method `indexOf` returns the index of the first occurrence of the specified value `val` in the linked
397
+ * list. If the value is not found, it returns -1.
257
398
  */
258
- DoublyLinkedList.prototype.get = function (index, by) {
259
- var _a, _b;
260
- if (by === void 0) { by = 'val'; }
261
- if (index < 0 || index >= this._size)
262
- return null;
263
- var count, current;
264
- if (index <= this._size / 2) {
265
- count = 0;
266
- current = this._first;
267
- while (count !== index) {
268
- current = current === null || current === void 0 ? void 0 : current.next;
269
- count++;
399
+ DoublyLinkedList.prototype.indexOf = function (val) {
400
+ var index = 0;
401
+ var current = this.head;
402
+ while (current) {
403
+ if (current.val === val) {
404
+ return index;
270
405
  }
406
+ index++;
407
+ current = current.next;
271
408
  }
272
- else {
273
- count = this._size - 1;
274
- current = this._last;
275
- while (count !== index) {
276
- current = current === null || current === void 0 ? void 0 : current.prev;
277
- count--;
409
+ return -1;
410
+ };
411
+ /**
412
+ * The `findLast` function iterates through a linked list from the last node to the first node and returns the last
413
+ * value that satisfies the given callback function, or null if no value satisfies the callback.
414
+ * @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This
415
+ * function is used to determine whether a given value satisfies a certain condition.
416
+ * @returns The method `findLast` returns the last value in the linked list that satisfies the condition specified by
417
+ * the callback function. If no value satisfies the condition, it returns `null`.
418
+ */
419
+ DoublyLinkedList.prototype.findLast = function (callback) {
420
+ var current = this.tail;
421
+ while (current) {
422
+ if (callback(current.val)) {
423
+ return current.val;
278
424
  }
425
+ current = current.prev;
279
426
  }
280
- switch (by) {
281
- case 'node':
282
- return current !== null && current !== void 0 ? current : null;
283
- case 'val':
284
- return (_a = current === null || current === void 0 ? void 0 : current.val) !== null && _a !== void 0 ? _a : null;
285
- default:
286
- return (_b = current === null || current === void 0 ? void 0 : current.val) !== null && _b !== void 0 ? _b : null;
427
+ return null;
428
+ };
429
+ /**
430
+ * The `toArrayReverse` function converts a doubly linked list into an array in reverse order.
431
+ * @returns The `toArrayReverse()` function returns an array of type `T[]`.
432
+ */
433
+ DoublyLinkedList.prototype.toArrayReverse = function () {
434
+ var array = [];
435
+ var current = this.tail;
436
+ while (current) {
437
+ array.push(current.val);
438
+ current = current.prev;
287
439
  }
440
+ return array;
288
441
  };
289
442
  /**
290
- * Updates the value of the node at the specified index.
291
- * If index = 0; Value of the first element in the list is updated.
292
- * If index = 3; Value of the fourth element in the list is updated.
293
- * @param index Index of the node to be updated
294
- * @param val New value of the node
443
+ * The `reverse` function reverses the order of the elements in a doubly linked list.
295
444
  */
296
- DoublyLinkedList.prototype.set = function (index, val) {
297
- var foundNode = this.get(index, 'node');
298
- if (foundNode !== null) {
299
- foundNode.val = val;
300
- return true;
445
+ DoublyLinkedList.prototype.reverse = function () {
446
+ var _a, _b;
447
+ var current = this.head;
448
+ _a = __read([this.tail, this.head], 2), this.head = _a[0], this.tail = _a[1];
449
+ while (current) {
450
+ var next = current.next;
451
+ _b = __read([current.next, current.prev], 2), current.prev = _b[0], current.next = _b[1];
452
+ current = next;
301
453
  }
302
- return false;
303
454
  };
304
- DoublyLinkedList.prototype.isEmpty = function () {
305
- return this._size === 0;
455
+ /**
456
+ * The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
457
+ * @param callback - The callback parameter is a function that takes two arguments: val and index. The val argument
458
+ * represents the value of the current node in the linked list, and the index argument represents the index of the
459
+ * current node in the linked list.
460
+ */
461
+ DoublyLinkedList.prototype.forEach = function (callback) {
462
+ var current = this.head;
463
+ var index = 0;
464
+ while (current) {
465
+ callback(current.val, index);
466
+ current = current.next;
467
+ index++;
468
+ }
306
469
  };
307
- // --- start extra methods ---
308
470
  /**
309
- * Inserts a new node at the specified index.
310
- * @param index Index at which the new node has to be inserted
311
- * @param val Value of the new node to be inserted
471
+ * The `map` function takes a callback function and applies it to each element in the DoublyLinkedList, returning a new
472
+ * DoublyLinkedList with the transformed values.
473
+ * @param callback - The callback parameter is a function that takes a value of type T (the type of values stored in
474
+ * the original DoublyLinkedList) and returns a value of type U (the type of values that will be stored in the mapped
475
+ * DoublyLinkedList).
476
+ * @returns The `map` function is returning a new instance of `DoublyLinkedList<U>` that contains the mapped values.
312
477
  */
313
- DoublyLinkedList.prototype.insert = function (index, val) {
314
- if (index < 0 || index > this._size)
315
- return false;
316
- if (index === 0)
317
- return !!this.addFirst(val);
318
- if (index === this._size)
319
- return !!this.addLast(val);
320
- var newNode = new DoublyLinkedListNode(val);
321
- var prevNode = this.get(index - 1, 'node');
322
- var nextNode = prevNode === null || prevNode === void 0 ? void 0 : prevNode.next;
323
- if (prevNode)
324
- prevNode.next = newNode;
325
- newNode.prev = prevNode;
326
- newNode.next = nextNode !== null && nextNode !== void 0 ? nextNode : null;
327
- if (nextNode)
328
- nextNode.prev = newNode;
329
- this._size++;
330
- return true;
478
+ DoublyLinkedList.prototype.map = function (callback) {
479
+ var mappedList = new DoublyLinkedList();
480
+ var current = this.head;
481
+ while (current) {
482
+ mappedList.push(callback(current.val));
483
+ current = current.next;
484
+ }
485
+ return mappedList;
331
486
  };
332
487
  /**
333
- * The `remove` function removes an element at a specified index from a data structure, updating the links between
334
- * nodes accordingly.
335
- * @param {number} index - The index parameter represents the position of the element to be removed in the data
336
- * structure. It is of type number.
337
- * @returns The `remove` method returns the value of the removed element (`T`) if the removal is successful, or `null`
338
- * if the index is out of bounds.
488
+ * The `filter` function iterates through a DoublyLinkedList and returns a new DoublyLinkedList containing only the
489
+ * elements that satisfy the given callback function.
490
+ * @param callback - The `callback` parameter is a function that takes a value of type `T` and returns a boolean value.
491
+ * It is used to determine whether a value should be included in the filtered list or not.
492
+ * @returns The filtered list, which is an instance of the DoublyLinkedList class.
339
493
  */
340
- DoublyLinkedList.prototype.remove = function (index) {
341
- var _a, _b, _c;
342
- if (index < 0 || index > this._size - 1)
343
- return null;
344
- else if (index === 0)
345
- return this.pollFirst();
346
- else if (index === this._size - 1)
347
- return (_b = (_a = this.pollLast('node')) === null || _a === void 0 ? void 0 : _a.val) !== null && _b !== void 0 ? _b : null;
348
- else {
349
- var prevNode = this.get(index - 1, 'node');
350
- var removeNode = prevNode === null || prevNode === void 0 ? void 0 : prevNode.next;
351
- var nextNode = removeNode === null || removeNode === void 0 ? void 0 : removeNode.next;
352
- if (prevNode)
353
- prevNode.next = nextNode !== null && nextNode !== void 0 ? nextNode : null;
354
- if (nextNode)
355
- nextNode.prev = prevNode;
356
- if (removeNode)
357
- removeNode.next = null;
358
- if (removeNode)
359
- removeNode.prev = null;
360
- this._size--;
361
- return (_c = removeNode === null || removeNode === void 0 ? void 0 : removeNode.val) !== null && _c !== void 0 ? _c : null;
494
+ DoublyLinkedList.prototype.filter = function (callback) {
495
+ var filteredList = new DoublyLinkedList();
496
+ var current = this.head;
497
+ while (current) {
498
+ if (callback(current.val)) {
499
+ filteredList.push(current.val);
500
+ }
501
+ current = current.next;
502
+ }
503
+ return filteredList;
504
+ };
505
+ /**
506
+ * The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
507
+ * single value.
508
+ * @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `val`. It is
509
+ * used to perform a specific operation on each element of the linked list.
510
+ * @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
511
+ * point for the reduction operation.
512
+ * @returns The `reduce` method is returning the final value of the accumulator after iterating through all the
513
+ * elements in the linked list.
514
+ */
515
+ DoublyLinkedList.prototype.reduce = function (callback, initialValue) {
516
+ var accumulator = initialValue;
517
+ var current = this.head;
518
+ while (current) {
519
+ accumulator = callback(accumulator, current.val);
520
+ current = current.next;
521
+ }
522
+ return accumulator;
523
+ };
524
+ /**
525
+ * The function inserts a new value after an existing value in a doubly linked list.
526
+ * @param {T} existingValue - The existing value is the value of the node after which we want to insert the new value.
527
+ * @param {T} newValue - The `newValue` parameter represents the value of the new node that you want to insert after
528
+ * the existing node.
529
+ * @returns The method is returning a boolean value. It returns true if the insertion is successful and false if the
530
+ * existing value is not found in the linked list.
531
+ */
532
+ DoublyLinkedList.prototype.insertAfter = function (existingValue, newValue) {
533
+ var existingNode = this.findNode(existingValue);
534
+ if (existingNode) {
535
+ var newNode = new DoublyLinkedListNode(newValue);
536
+ newNode.next = existingNode.next;
537
+ if (existingNode.next) {
538
+ existingNode.next.prev = newNode;
539
+ }
540
+ newNode.prev = existingNode;
541
+ existingNode.next = newNode;
542
+ if (existingNode === this.tail) {
543
+ this.tail = newNode;
544
+ }
545
+ this.length++;
546
+ return true;
362
547
  }
548
+ return false;
549
+ };
550
+ /**
551
+ * The `insertBefore` function inserts a new value before an existing value in a doubly linked list.
552
+ * @param {T} existingValue - The existing value is the value of the node that you want to insert the new value before.
553
+ * @param {T} newValue - The `newValue` parameter represents the value of the new node that you want to insert before
554
+ * the existing node.
555
+ * @returns The method is returning a boolean value. It returns true if the insertion is successful and false if the
556
+ * existing value is not found in the linked list.
557
+ */
558
+ DoublyLinkedList.prototype.insertBefore = function (existingValue, newValue) {
559
+ var existingNode = this.findNode(existingValue);
560
+ if (existingNode) {
561
+ var newNode = new DoublyLinkedListNode(newValue);
562
+ newNode.prev = existingNode.prev;
563
+ if (existingNode.prev) {
564
+ existingNode.prev.next = newNode;
565
+ }
566
+ newNode.next = existingNode;
567
+ existingNode.prev = newNode;
568
+ if (existingNode === this.head) {
569
+ this.head = newNode;
570
+ }
571
+ this.length++;
572
+ return true;
573
+ }
574
+ return false;
363
575
  };
364
576
  return DoublyLinkedList;
365
577
  }());