Created
March 17, 2014 04:55
-
-
Save ionox0/9594186 to your computer and use it in GitHub Desktop.
Iterative List Reverse
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
function reverse(list){ | |
var temp = []; | |
while (list != null){ | |
temp.push(list.head); | |
list = list.tail; | |
} | |
var newList = { | |
head: temp.shift, | |
tail:null | |
} | |
while (temp.length != 0){ | |
newList = { | |
head: temp.shift(), | |
tail: newList | |
} | |
} | |
return newList; | |
} | |
var numbers = { head:1, tail:{ head:2, tail:{ head:3, tail:null }}}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment