Showing posts with label ARRAY IMPLEMENTATION OF QUEUE. Show all posts
Showing posts with label ARRAY IMPLEMENTATION OF QUEUE. Show all posts

Friday, February 21, 2014

ARRAY IMPLEMENTATION OF QUEUE

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)
}