import java.util.Stack;
public class Reverse{
class LNode{
int data;
LNode next;
public LNode(int data){
this.data=data;
}
}
public static void main(String []args){
Reverse r = new Reverse();
for(int i=1;i<=10;i++){
r.add(i);
}
r.print(r.head);
}
public void add(int i){
if(head==null){
head=new LNode(i);
current = head;
}else{
current.next=new LNode(i);
current = current.next;
}
}
public void print(LNode node){
if(node==null) return;
current = node;
while(current!=null){
System.out.println(current.data);
current=current.next;
}
}
}
Language Version: JDK 10.0.1