import com.doubleLinkedList.Node; public class ReverseList { public Node ReverseList1(Node head){ Node current=head; Node prevnode=null; Node newhead=null; if(current==null){ throw new NullPointerException("no node this listnode!"); } while(current!=null){ Node nextnode=current.next; current.next=prevnode; if(nextnode==null){ newhead=current; } prevnode=current; current=nextnode; } return newhead; } }
时间: 2024-10-12 14:59:27