We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
function reversePrint(llist) {
// Write your code here
if (llist === null) {
return
} else {
// reverse the list
let current = llist;
let prev = null;
while (current !== null) {
let next = current.next;
current.next = prev;
prev = current;
current = next;
};
//print the reverse list
let reversed = prev;
for (; reversed !== null; reversed = reversed.next) {
console.log(reversed.data);
};
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Print in Reverse
You are viewing a single comment's thread. Return to all comments →
solution
function reversePrint(llist) { // Write your code here if (llist === null) { return } else { // reverse the list let current = llist; let prev = null;
}