本文共 712 字,大约阅读时间需要 2 分钟。
function Node(value){ this.value = value; this.next = null; } var node1 = new Node(1); var node2 = new Node(2); var node3 = new Node(3); var node4 = new Node(4); var node5 = new Node(5); node1.next=node2; node2.next=node3; node3.next=node4; node4.next=node5; // 链表遍历 function bian(root){ if(root== null){ return; }else{ console.log(root); bian(root.next); } } // bian(node1); //链表逆置 function niZhi(root){ if(root.next == null){ return root; }else{ // 逆置链表 var result = niZhi(root.next); root.next.next = root; root.next = null; console.log(root) return result; } } var node = niZhi(node1); bian(node);
转载地址:http://myyg.baihongyu.com/