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 215fb21 commit 046e803Copy full SHA for 046e803
src/data-structures/linked-list/LinkedList.js
@@ -329,4 +329,23 @@ export default class LinkedList {
329
330
return currNode.value;
331
}
332
+
333
+ /**
334
+ * Print the entire list.
335
+ */
336
+ print() {
337
+ if (this.getSize() === 0) return ''; // check if the list size is zero;
338
+ let res = '';
339
+ let currNode = this.head;
340
341
+ // Iterate the list to add values to res variable
342
+ while (currNode) {
343
+ res += `${currNode.value} ==> `;
344
+ currNode = currNode.next;
345
+ }
346
347
+ res += `null`;
348
349
+ console.log(res);
350
351
0 commit comments