PROGRAM:
import java.io.*;
import java.lang.*;
class data
{
int i,x;
int a[]=new,int[10];
int rear=-1;
int front=0;
void inqueue() throws IOException
{
DataInput Stream in = new DataInputStream(System.in);
System.out.println("enter the elements");
x=Integer.parseInt(in,readLine());
if(rear>=5)
{
System.out.println("overflow");
}
else
{
rear=rear+1;
a[rear]=x;
}}
void Dequeue() throws IOException
{
if(front>rear)
}
System.out.println("overflow");
else
{front=front+1;
}}void display()throws IOExcetion
{
for (i=front;i<=rear;i++)
{
System.out.println("the elements ;"+a[i]);
}
}
}
class queue
{
public static void main(string args[])throws IOException
{
Data d=new Data();
DatainputStream in=new DataInputStream(System.in);
int i,x,c;
int a[]=new int[10];
do
{
System.out.println("enter the choice");
c=Integer.parseInt(in.readline());
switch(c)
{
case 1:
d.enqueue();
break;
case 2:
d.dequeue();
case 3:
d.display();
break;
}
}
while(c<=3)
}
OUTPUT:
enter your choice:1
enter the elements:30
enter your choice:2
enter the elements:20
enter your choice:1
enter the elements:10
enter your choice:3
elements:
30
20
10
enter your choice:2
10
enter your choice:3
30
20
No comments:
Post a Comment