// Generated by CoffeeScript 1.9.3varListNode,head,result,reverse_linkedList;ListNode=(function(){functionListNode(val){this.val=val;this.next=null;}returnListNode;})();reverse_linkedList=function(head){varnext_one,p,start;p=head;start=null;while(p){next_one=p.next;p.next=start;start=p;p=next_one;}returnstart;};head=newListNode(1);head.next=newListNode(2);head.next.next=newListNode(3);result=reverse_linkedList(head);while(result){console.log(result.val);result=result.next;}
// Generated by CoffeeScript 1.9.3varListNode,head,result,reverse_linkedList;ListNode=(function(){functionListNode(val){this.val=val;this.next=null;}returnListNode;})();reverse_linkedList=function(head){varresult,second;if(head===null||head.next===null){returnhead;}second=head.next;head.next=null;result=reverse_linkedList(second);second.next=head;returnresult;};head=newListNode(1);head.next=newListNode(2);head.next.next=newListNode(3);result=reverse_linkedList(head);while(result){console.log(result.val);result=result.next;}