Skip to content

Instantly share code, notes, and snippets.

@kreegr
Created May 5, 2015 21:50
Show Gist options
  • Save kreegr/f98355d575cb22d52a34 to your computer and use it in GitHub Desktop.
Save kreegr/f98355d575cb22d52a34 to your computer and use it in GitHub Desktop.
// I'm dumb
var go = function() {
var LLNode = function LLNode(i) {
this.i = i;
};
var i = 1;
var headNode = new LLNode(i);
var node = headNode;
// build
for (i; i < 100; i++) {
node.nextNode = new LLNode(i);
node = node.nextNode;
}
node = headNode;
var nextNode = node.nextNode;
var prevNode;
while(nextNode) {
console.log(node.i);
nextNode = node.nextNode;
node.nextNode = prevNode;
if (nextNode){
prevNode = node;
node = nextNode;
}
}
while (node) {
console.log(node.i);
node = node.nextNode;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment