We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b3895a4 commit bcc9a8bCopy full SHA for bcc9a8b
Data Structures/Linked Lists/doubleLinkedList.js
@@ -98,15 +98,28 @@ class DoublyLinkedList {
98
this.size--;
99
}
100
101
+
102
+ // Return the doubly linked list as string
103
+ toStringify() {
104
+ let current = this.head;
105
+ let string = "";
106
107
+ while (current) {
108
+ string += current.data + (current.next ? "\n" : "");
109
+ current = current.next;
110
+ }
111
+ return string;
112
113
114
115
const dbl = new DoublyLinkedList();
116
117
dbl.insert(100, 0);
118
dbl.insert(200, 0);
-dbl.insert(400, 0);
119
dbl.insert(300, 1);
120
+dbl.insert(400, 3);
121
dbl.insert(500, 3);
-dbl.remove(1);
122
+dbl.remove(3);
123
124
console.log(dbl);
125
+console.log(dbl.toStringify());
0 commit comments