/* QUEUE USING ARRAY */
import java.io.*;
class Q
{
int front,rear,a[],n;
DataInputStream nn=new
DataInputStream(System.in);
void read()
{try
{
System.out.print("enter the limit :
");
n=Integer.parseInt(nn.readLine());
a=new int[n];
front=0;
rear=0;
}
catch(Exception e)
{}}
void EnQ()
{try
{
if(rear==n)
System.out.println("Q is full");
else
{
System.out.print("Enter the
number: ");
int d=Integer.parseInt(nn.readLine());
a[rear]=d;
rear++;
}}
catch(Exception e)
{}}
void DeQ()
{
if(front==rear)
System.out.print("Q is empty");
else
{
int d=a[front];
front++;
System.out.print("deleted element is
"+ d);
}}
void display()
{
if(front==rear)
System.out.print("no elements ");
else
{
for(int i=front;i<rear;i++)
System.out.println(a[i]);
}}}
class MQ
{
public static void main(String args[])
{
try
{DataInputStream get=new
DataInputStream(System.in);
int p;
Q obj=new Q();
obj.read();
do
{
System.out.println("1.EnQ\n2.DeQ\n3.Display\n");
System.out.print("Enter the
choice: ");
int ch=Integer.parseInt(get.readLine());
p=ch;
switch(ch)
{
case 1: obj.EnQ();break;
case 2: obj.DeQ();break;
case 3: obj.display();
}
}while(p<4);
}
catch(Exception e)
{}
}}
OUTPUT
enter the limit : 2
1.EnQ
2.DeQ
3.Display
Enter the choice: 1
Enter the number: 1
1.EnQ
2.DeQ
3.Display
Enter the choice: 1
Enter the number: 2
1.EnQ
2.DeQ
3.Display
Enter the choice: 1
Q is full
1.EnQ
2.DeQ
3.Display
Enter the choice: 3
1
2
1.EnQ
2.DeQ
3.Display
Enter the choice: 2
deleted element is 1
1.EnQ
2.DeQ
3.Display
Enter the choice: 2
deleted element is 2
1.EnQ
2.DeQ
3.Display
Enter the choice: 2
Q is empty
1.EnQ
2.DeQ
3.Display
Enter the choice: 3
no elements
1.EnQ
2.DeQ
3.Display
Enter the choice: 4






0 comments:
Post a Comment