Guest User

Untitled

a guest
Jun 24th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. public static Node reverse(Node curr, Node ogHead) {
  2. // base case if we end up back at the head of the original list return
  3. // our new list
  4. if (curr == ogHead) {
  5. return ogHead;
  6. }
  7.  
  8. // ogHead is initiall setup to be the tail of curr now the current node
  9. // of curr is added to ogHead
  10. ogHead.addNodeAfter(curr.getData());
  11.  
  12. // set the curr node equal to the next node in the list
  13. curr = curr.getLink();
  14. // call the method again with the new current element and the updated
  15. // new list
  16.  
  17. reverse(curr, ogHead);
  18.  
  19. return ogHead;
  20.  
  21. }
Add Comment
Please, Sign In to add comment