您的位置:首页 > 其它

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

2016-11-09 17:48 375 查看
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;

}

}

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐