Created
December 1, 2015 14:46
-
-
Save kharandziuk/94903e6e45ffb2b837f9 to your computer and use it in GitHub Desktop.
This file contains 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
class N | |
constructor: (val, next) -> | |
@val = val | |
@next = next | |
assert = require('assert') | |
reverse = (node, prev) => | |
if not node? | |
assert(prev?) | |
return prev | |
newPrev = new N(node.val, prev) | |
return reverse(node.next, newPrev) | |
iter = (node) -> | |
if not node? | |
return | |
console.log(node.val) | |
iter(node.next) | |
iter(reverse(new N(1, new N(2, new N(4))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment