import java.util.*;
import java.io.*;
class linkl
{
public static void main(String arg[])throws IOException
{
LinkedList list=new LinkedList();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int pos,ch;
String item;
while(true)
{
System.out.println("1.Add First into the list");
System.out.println("2.Add Last into the list");
System.out.println("3.Add At the specific Position");
System.out.println("4.Remove At the specific Position");
System.out.println("5.Size Of List");
System.out.println("6.Display Items");
System.out.println("Enter Your Choice");
item=br.readLine();
ch=Integer.parseInt(item);
switch(ch)
{
case 1 : System.out.println("Enter Item To Store");
item=br.readLine();
list.addFirst(item);
System.out.println("..........................................");
break;
case 2: System.out.println("Enter Item To Store");
item=br.readLine();
list.addLast(item);
System.out.println("..........................................");
break;
case 3: System.out.println("Enter Position");
item=br.readLine();
pos=Integer.parseInt(item);
System.out.println("Enter Item To Store");
item=br.readLine();
try
{
list.add(pos,item);
}
catch(Exception e)
{
System.out.println("Invalid Position");
}
System.out.println("..........................................");
break;
case 4: System.out.println("Enter Position To Delete");
item=br.readLine();
pos=Integer.parseInt(item);
try
{
list.remove(pos);
}
catch(Exception e)
{
System.out.println("Invalid Position");
}
System.out.println("..........................................");
break;
case 5: System.out.println("Size Of List:"+list.size());
System.out.println("..........................................");
break;
case 6: System.out.println("Items In The List");
System.out.println(list);
System.out.println("..........................................");
break;
default:
System.exit(1);
}
}
}
}
import java.io.*;
class linkl
{
public static void main(String arg[])throws IOException
{
LinkedList list=new LinkedList();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int pos,ch;
String item;
while(true)
{
System.out.println("1.Add First into the list");
System.out.println("2.Add Last into the list");
System.out.println("3.Add At the specific Position");
System.out.println("4.Remove At the specific Position");
System.out.println("5.Size Of List");
System.out.println("6.Display Items");
System.out.println("Enter Your Choice");
item=br.readLine();
ch=Integer.parseInt(item);
switch(ch)
{
case 1 : System.out.println("Enter Item To Store");
item=br.readLine();
list.addFirst(item);
System.out.println("..........................................");
break;
case 2: System.out.println("Enter Item To Store");
item=br.readLine();
list.addLast(item);
System.out.println("..........................................");
break;
case 3: System.out.println("Enter Position");
item=br.readLine();
pos=Integer.parseInt(item);
System.out.println("Enter Item To Store");
item=br.readLine();
try
{
list.add(pos,item);
}
catch(Exception e)
{
System.out.println("Invalid Position");
}
System.out.println("..........................................");
break;
case 4: System.out.println("Enter Position To Delete");
item=br.readLine();
pos=Integer.parseInt(item);
try
{
list.remove(pos);
}
catch(Exception e)
{
System.out.println("Invalid Position");
}
System.out.println("..........................................");
break;
case 5: System.out.println("Size Of List:"+list.size());
System.out.println("..........................................");
break;
case 6: System.out.println("Items In The List");
System.out.println(list);
System.out.println("..........................................");
break;
default:
System.exit(1);
}
}
}
}
No comments:
Post a Comment