Java:如何实现链表的反转

来源:互联网 发布:bcg矩阵是什么意思 编辑:程序博客网 时间:2024/06/04 17:41
public class reverseiteratively {public static void method(Node head) {Node p1=head;Node p2=head.next;Node temp=null;while(p2.next!=null) {temp=p2.next;p2.next=p1;p1=p2;p2=temp;}p2.next=p1;head=p2;}}