class trylinklist3 {
	
	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;

	// keep track of the list size
	int list_size=0;

	// creating first node and attach it to the list
	for(int i=0;i<20; i++){	
		list_node	N= new list_node(i+1);

		if(mylist==null) { 
			mylist=N; 
			tmp=N; 
		} 
		else {
			tmp.link=N;
			tmp=tmp.link;
		}
		list_size++;
	}

// to print the list
	System.out.println(" Original list : - ");
	tmp=mylist;	

	for(int i=0;i<list_size; i++){
		System.out.println(tmp.data);	
		tmp=tmp.link;
	}
	
	reverselist(mylist,list_size);

	}

///////////////////////////////////////////////////////
// to reverse the list
///////////////////////////////////////////////////////
	public	static void	reverselist(list_node mylist,int list_size)
	{
	
	list_node	mynewlist= null;

	list_node	tmp=null;

	for(int i=0;i<list_size; i++){
		list_node	tmp2=new list_node();
		tmp2=mylist;
		mylist=mylist.link;
		tmp2.link=mynewlist;
		mynewlist=tmp2;
	}

// to print the list after reversing
	System.out.println(" List after reversing : - ");
	tmp=mynewlist;
	for(int i=0;i<list_size; i++){
		System.out.println(tmp.data);	
		tmp=tmp.link;
	}

	}
///////////////////////////////////////////////////////

}