Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Node reverse(Node curr, Node ogHead) {
- // base case if we end up back at the head of the original list return
- // our new list
- if (curr == ogHead) {
- return ogHead;
- }
- // ogHead is initiall setup to be the tail of curr now the current node
- // of curr is added to ogHead
- ogHead.addNodeAfter(curr.getData());
- // set the curr node equal to the next node in the list
- curr = curr.getLink();
- // call the method again with the new current element and the updated
- // new list
- reverse(curr, ogHead);
- return ogHead;
- }
Add Comment
Please, Sign In to add comment