Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ListItem reverse_i() {
- ListItem curr = this;
- ListItem prev = null;
- while (curr != null) {
- // Store the next item in the list
- ListItem next = curr.next;
- // Set the current ListItem's next value to the previous ListItem
- curr.next = prev;
- // Set the previous equal to the current value
- prev = curr;
- // Move curr along
- curr = next;
- }
- return prev;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement