Skip to content

Instantly share code, notes, and snippets.

@ionox0
Created March 17, 2014 04:55
Show Gist options
  • Save ionox0/9594186 to your computer and use it in GitHub Desktop.
Save ionox0/9594186 to your computer and use it in GitHub Desktop.
Iterative List Reverse
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