Skip to content

Instantly share code, notes, and snippets.

@kanikash4
Last active October 10, 2017 18:38
Show Gist options
  • Save kanikash4/eacc7652c72d103af49a5ec35b5c98c4 to your computer and use it in GitHub Desktop.
Save kanikash4/eacc7652c72d103af49a5ec35b5c98c4 to your computer and use it in GitHub Desktop.
Javascript: Reverse a Linked list
var list = {
name : 'I',
next : {
name : 'AM',
next : {
name : 'KANIKA',
next : {
name : 'SHARMA'
}
}
}
};
function reverse(list) {
if(list.next) {
reverse(list.next);
console.log(list.name);
}
else {
console.log(list.name);
}
}
reverse(list);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment