标签:
原理:使用三个指针,p,q指向交换的元素,r指向后续元素
代码如下:
class Node{
	int data;
	Node next; 
	Node(int data){
		this.data=data;
	}
}
 Node reverse(Node head) {
		if(head==null || head.next==null) return head;
		Node p=head,q=p.next,r=q.next;
		q.next=p;p.next=null;
		while(r!=null){
			p=q;
			q=r;
			r=r.next;
			q.next=p;
		}
		return q;
	}
}
标签:
原文地址:http://www.cnblogs.com/mlz-2019/p/5008053.html