* and open the template in the editor.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package link_list;
/**
*
* @author shalabh
*/
import java.io.*;
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args)throws Exception {
// TODO code application logic here
DataInputStream k=new DataInputStream(System.in);
int a,ans=1;
List L=new List();
L.a=Integer.parseInt(k.readLine());
L.N=null;
System.out.println("1:Insertion");
System.out.println("2:Removal");
System.out.println("3:Searching");
System.out.println("4:Display");
System.out.println("5:Exit");
List L1,L2;
int pos,i=0,term,ct=1;
L1=null;
L1=L;
L2=L;
L2.N=null;
while(true)
{ ans=Integer.parseInt(k.readLine());
i=0;
if(ans==1)
{ ct++;
L1 =new List();
L1.a=Integer.parseInt(k.readLine());
//L.N=L1;
L.N=L1;
L=L.N;
L.N=null;
}
if(ans==2)
{
i=0;
L1=L2;
if(L==L2)
{
System.out.println("UnderFlow");
continue;
}
pos=Integer.parseInt(k.readLine());
System.out.println("L2.a:"+L2.a);
System.out.println("L.a:"+L.a);
while(i!=(pos-1))
{ i++;
L1=L1.N;
}
System.out.println("ELEMENT:"+L1.a);
if(pos!=ct)
{ if(L1.N.N!=null)
{L1.N=L1.N.N;
System.out.println("yes");
}
}
else
{System.out.println(L1.a);
L1.N=null;
}
ct--;
}
if(ans==3)
{
term=Integer.parseInt(k.readLine());
L1=L2;
while(L1.N.a!=term)
L1=L1.N;
if(L1.N!=null)
System.out.println(L1.N);
else
System.out.println("NOT Found");
}
if(ans==4)
{ System.out.println("List");
L1=L2;
while(L1.N!=null)
{
System.out.println(L1.a);
L1=L1.N;
}
System.out.println(L1.a);
}
if(ans==5)
{
break;
}
}
}
}