You are viewing a single comment's thread. Return to all comments →
public static SinglyLinkedListNode reverse(SinglyLinkedListNode llist) {
if(llist == null) return null; if(llist.next == null) return llist;
SinglyLinkedListNode curr = llist; SinglyLinkedListNode prev = null; SinglyLinkedListNode temp = null; while(curr != null){ temp = curr.next; //point curr node to prev curr.next = prev; //set prev = curr node prev = curr; curr = temp; } return prev; }
Seems like cookies are disabled on this browser, please enable them to open this website
Reverse a linked list
You are viewing a single comment's thread. Return to all comments →
if(llist == null) return null; if(llist.next == null) return llist;