let traverseList = function(linkedList){
var current = this.start;
while (current !== null) {
// do something which the current node
current = current.next;
}
}
iterative
var reverseList = function(head) {
let current = head;
if (!current) {
return current;
}
let curPre = head.next;
current.next = null;
while (curPre) {
// save the next node
let tmp = curPre.next;
curPre.next = current;
current = curPre;
curPre = tmp;
}
return current;
};
var reverseList = function(head){
if (!head) { return head; }
let pre = head.next;
head.next = null;
return fun(head, pre);
function fun(cur, pre){
if (pre == null) { return cur; }
let tmp = pre.next;
pre.next = cur;
return fun(pre, tmp); }
}
ID: 5766
NAME: code-quiz-question
DESCRIPTION: code-quiz-question - reversing a linked list -
AUTHOR: article.author/s
EDITOR: article.editor/s
PUBLISHER: article.publisher/s
STATUS: Write
PRIORITY: -5
OWNER ID: 75