输入一个链表,反转链表后,输出链表的所有元素

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;
        
        
        
        
    }
    
    
    
    
    
    
}
原文地址:https://www.cnblogs.com/luo-mao/p/6047914.html