AlgoCasts icon indicating copy to clipboard operation
AlgoCasts copied to clipboard

where is reverse a linked list methodology?

Open akash5324 opened this issue 6 years ago • 1 comments

akash5324 avatar Oct 04 '18 01:10 akash5324

https://www.geeksforgeeks.org/reverse-a-linked-list/

reverse() { if (this.head) { // p n c // null 1, 2, 3, 4, 5 null

  let current = null;
  let previous = null;
  let node = this.head;

  while (node) {
    current = node;
    node = node.next;
    current.next = previous;
    previous = current;
  }

  return previous;
}

}

anuragarwalkar avatar Dec 30 '21 08:12 anuragarwalkar