We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Reverse a linked list
Reverse a linked list
Sort by
recency
|
881 Discussions
|
Please Login in order to post a comment
here if you go with prev; and curr then you would get the same answer without loop. while (curr!==null) { ahead = curr.next; curr.next = prev; prev = curr; curr = ahead; }
here
Another JS solution
SinglyLinkedListNode curr = llist; SinglyLinkedListNode prev = null; SinglyLinkedListNode nextnode = null;
if(curr.next!=null)
{
}
return prev;
Javascript code
function reverse(llist) { let curr = llist; let prev = null; let ahead = null;
}