JS反转链表
迭代,改变每个节点指针指向之后移动
function ReverseList(pHead)
{
// write code here
if (pHead === null || pHead.next === null) return pHead;
let cur = pHead;
let pre = null;
let nxt;
while (cur) {
nxt = cur.next;
cur.next = pre; // 改变指针
// 移动
pre = cur;
cur = nxt;
}
return pre;
}
[1]: https://segmentfault.com/a/1190000037518253