2
 function reverse(list){
  2     var p=list.head,q=null;
  3     while(p.next!==null){
  4         q=p.next;
  5         p.next=q.next;
  6         q.next=list.head.next;
  7         list.head.next=q;
  8     }
  9     return list;
 10 }

定义两个指针P,Q;
Q是P的next;
贯穿的思想是将P后面的一个插入到Head之后,后面的连接起来;
前提是P的后一个非空

最笨的方法:将其存储为数组,数组逆序再存为链表,浪费空间和时间


_ipo
179 声望15 粉丝

bug