class trylinklist2 { public static void main(String [] args){ // creating my list // starting by empty list list_node mylist=null; // temp node to run while creating the nodes list_node tmp=null; // creating nodes and attach it to the list for(int i=0;i<3; i++){ //********** NEW ** loop list_node N= new list_node(i+1); if(mylist==null){ // if this is the first one in the list mylist=N; tmp=N; } else{ tmp.link=N; tmp=tmp.link; } } // other nodes creation deleted // to print the list if(mylist!=null){ tmp=mylist; System.out.println(tmp.data); while(tmp.link!=null){ //********** NEW ** loop tmp=tmp.link; System.out.println(tmp.data); } } } }