Last active
October 10, 2017 18:38
-
-
Save kanikash4/eacc7652c72d103af49a5ec35b5c98c4 to your computer and use it in GitHub Desktop.
Javascript: Reverse a Linked list
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
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