/*function ListNode(x){
this.val = x;
this.next = null;
}*/
function ReverseList(pHead)
{
// write code here
if(pHead == null){
return null;
}
let pCur = pHead;
let pNext = null;
let pLast = null;
while(pCur !== null){
pNext = pCur.next;
pCur.next = pLast;
pLast = pCur;
pCur = pNext;
}
return pLast;
}
function ReverseList2(pHead)
{
// write code here
if(pHead == null || pHead.next == null){
return pHead;
}
let newHead = ReverseList2(pHead.next);
let pNext = pHead.next;
pNext.next = pHead;
pHead.next = null;
return newHead;
}
let node3 = {
val:3,
next:null
}
let node2 = {
val:2,
next:node3
}
let node1 = {
val:1,
next:node2
}
function ShowList(pHead){
if(pHead == null){
return;
}
let pCur = pHead;
while(pCur){
console.log(pCur.val);
pCur = pCur.next;
}
}
console.log("Show List:");
ShowList(node1);
let newHead = ReverseList2(node1);
console.log("Show List 222:");
ShowList(newHead);