showing results for - "reverse a linked list js"
Nick
17 Nov 2016
1// O(n) time & O(n) space
2function reverse(head) {
3  if (!head || !head.next) {
4    return head;
5  }
6  let tmp = reverse(head.next);
7  head.next.next = head;
8  head.next = undefined;
9  return tmp;
10}
11
Betty
31 Feb 2019
1function LinkedListNode(value) {
2  this.value = value;
3  this.next = null;
4}
5let head = new LinkedListNode(10)
6head.next = new LinkedListNode(25)
7head.next.next = new LinkedListNode(46)
8
9// Recursive
10const reverse = (head) => {
11 if (!head || !head.next) {
12   return head;
13 }
14 let temp = reverse(head.next);
15 head.next.next = head;
16 head.next = undefined;
17 return temp;
18}
19head = reverse(head)
queries leading to this page
js reverse a doubly linked listhow to reverse a linked list jsreverse linked list in javascriptreverse a linked list return head javascriptreverse values in linked list javascripthow to reverse the linked list in jsreverse a linked list i javacsriptreverse a linked list jshow to reverse a linked list in javascripthow to reverse linked list jsreverse linked list jslinked list reverse program javascirptjavascript recursion linked listreverse linked list using recursion kjavascriptreverse a linked list in place jshow to reverse linked list javascriptjavascipt reverse linked list constant spacejs combine linked listhow to reverse a linked list without using data structure javascriptreversing a linked list javascripthow to reverse a singly linked list in javascriptlinked list reverse in jsreverse linked list program in javascriptreverse linked list using recursion javascriptreverse a linkedlist jsjavascript reverse linked listlinked list print in reverse in jsreverse linked list algorithm javascriptjavascript function reverse linked listlinkedlist js reversereverse linked list with jsreverse linked list in place jsreverse a linked list c 2b 2breverse and return a singly linked list jspython how to print head of linked listfunction to reverse a singly linked list javascripthow to reverse a linked list javascript mediumjavascript reverse a linkedlistreverse singly linked list javascript reversing a linked list in javascriptreverse a linked list javascriptreverse a linked list in jsreverse a singly linked list in jsreverse singly linked list jshow to reverse a linked list in javascriptjs reverse linked listprint linked list in reverse in jsinvert a linked list javascriptreverse linked list in jsreverse singly linked list javascript algorithmes6 reverse linked listjavascipt reverse linked listreversed singly linked list recursively javascriptreverse link list in jsjavascript reverse a linked list206 reverse linked list javascriptreverse link list in javascriptreverse a singly linked list in javascriptreversing a linked list jslinked list reversal javascriptreverse doubly linked list javascriptreverse a list in javascriptreversee a linked list jsreverse a singly linked list javascriptjavascript run linked list backwardsho to reverse a linked list javascripthow to reverse linked list in jsreverse singly linked list in javascriptlinkedlist reverse jsreverse listnode jshow to reverse a single linkedlist javascripthow to display linked list in reverse order in javascripthow to reverse a singly linked list jsreverse linked list javascripthow to reverse a linked list javascriptjavascript reverse 28 29 on a linked listreverse linked list solution jsreverse a linked list in javascript reverse linked list javascript how to reverse a linked list in jsreverse linked list algo jslearn linked list reverse in javascriptreversed linked list jsreverse link list javascriptreverse a linked list js