输入 1->2->3->4
输出4->3->2->1
public class LinkNode {
public static void main(String[] args) {
Node n1= new Node(1);
Node n2= new Node(2);
Node n3= new Node(3);
Node n4= new Node(4);
n1.node=n2;
n2.node=n3;
n3.node=n4;
n4.node=null;
Node head=n1;
Node newhead =null;
Node temp;
while(head!=null){
temp=head.node;
head.node=newhead;
newhead=head;
head=temp;
}
while(newhead!=null){
System.out.println(newhead.val);
newhead=newhead.node;
}
}
}
class Node{
int val;
Node node;
public Node(int val){
this.val=val;
}