class trylinklist1 { 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 first node and attach it to the list list_node N1= new list_node(); N1.data =1; N1.link =null; mylist=N1; // since its the first node tmp=N1; // creating second node and attach it to the list list_node N2= new list_node(); N2.data =2; N2.link =null; tmp.link=N2; tmp=tmp.link; // creating third node and attach it to the list list_node N3= new list_node(); N3.data =3; N3.link =null; tmp.link=N3; tmp=tmp.link; // to print the list if(mylist!=null){ tmp=mylist; // point to the first node System.out.println(tmp.data); tmp=tmp.link; // move to the next System.out.println(tmp.data); tmp=tmp.link; // move to the next System.out.println(tmp.data); } } }