/** 较原创文章有改动
*/
public class Node
{
int data;
Node next=null;
public Node(int data){
this.data=data;
}
public static Node reverse(Node head){
Node p=null;
Node q=head;
while(head!=null){
q=head.next;
head.next=p;
p=head;
head=q;
}
return p;
}
public static void main(String[] args) {
Node head=new Node(0);
Node tail=head;
for(int i=1;i<10;i++){
Node p=new Node(i);
tail.next=p;
tail=p;
}
head=reverse(head);
while(head!=null){
System.out.println(head.data);
head=head.next;
}
}
}