Created
April 16, 2015 18:29
-
-
Save kenmazaika/20a959073130904936f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def reverse_list!(head, previous_element = nil) | |
| next_iter = head.next_element # keep track of next iteration step | |
| head.next_element = previous_element # flip-flip list pointer | |
| return head if next_iter.nil? # return results accumulator if done | |
| reverse_list!(next_iter, head) # otherwise, recursive traversal | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment