import java.io.*;
class qlin
{
int item;
qlin next;
}
class queue
{
int i=0;
qlin first,prev,curr;
void insert(int x)
{
i++;
if(i==1)
{
first=new qlin();
first.item=x;
first.next=null;
prev=first;
}
else
{
curr=new qlin();
curr.item=x;
curr.next=null;
prev.next=curr;
prev=curr;
}
}
void delete()
{
if(i==0)
{
System.out.println("queue is empty");
}
else
{
i--;
curr=first;
System.out.println("Deleted Element="+curr.item);
first=first.next;
curr=null;
}
System.out.println();
}
void display()
{
curr=first;
while(curr!=null)
{
System.out.println(curr.item);
curr=curr.next;
}
System.out.println();
}
}
class queuelin
{
public static void main(String []args) throws IOException
{
queue ql=new queue();
int ch,x;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
while(true)
{
System.out.println("1.Insert");
System.out.println("2.Delete");
System.out.println("3.SHOW");
System.out.println("4.EXIT");
System.out.println("Enter Ur Choice:");
ch=Integer.parseInt(br.readLine());
switch(ch)
{
case 1: System.out.println("Enter a Number:");
x=Integer.parseInt(br.readLine());
ql.insert(x);
break;
case 2: ql.delete();
break;
case 3: ql.display();
break;
case 4: System.exit(0);
}
}
}
}
class qlin
{
int item;
qlin next;
}
class queue
{
int i=0;
qlin first,prev,curr;
void insert(int x)
{
i++;
if(i==1)
{
first=new qlin();
first.item=x;
first.next=null;
prev=first;
}
else
{
curr=new qlin();
curr.item=x;
curr.next=null;
prev.next=curr;
prev=curr;
}
}
void delete()
{
if(i==0)
{
System.out.println("queue is empty");
}
else
{
i--;
curr=first;
System.out.println("Deleted Element="+curr.item);
first=first.next;
curr=null;
}
System.out.println();
}
void display()
{
curr=first;
while(curr!=null)
{
System.out.println(curr.item);
curr=curr.next;
}
System.out.println();
}
}
class queuelin
{
public static void main(String []args) throws IOException
{
queue ql=new queue();
int ch,x;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
while(true)
{
System.out.println("1.Insert");
System.out.println("2.Delete");
System.out.println("3.SHOW");
System.out.println("4.EXIT");
System.out.println("Enter Ur Choice:");
ch=Integer.parseInt(br.readLine());
switch(ch)
{
case 1: System.out.println("Enter a Number:");
x=Integer.parseInt(br.readLine());
ql.insert(x);
break;
case 2: ql.delete();
break;
case 3: ql.display();
break;
case 4: System.exit(0);
}
}
}
}
No comments:
Post a Comment