DSA: Queue Implementation Using Arrays
class Qu
{
int a[],front=-1,rear=-1,max,count=0;
Qu(int size)
{
a=new int[size];
max=size;
}
void enQ(int x)
{
if(isFull())
{
System.out.println("Q is Full");
}
else if(isEmpty())
{
front++;
rear++;
a[rear]=x;
}
else
{
a[rear]=x;
rear++;
}
}
public void dQ()
{
int item;
if(isEmpty())
{
System.out.println("Q is Empty");
}
else
{
System.out.println("Element \t "+a[front]+"\t deleted from Q");
front++;
}
if(front==rear)
{
front=-1;
rear=-1;
}
}
public boolean isEmpty()
{
if(((front==-1)&&(rear==-1)))
return true;
else
return false;
}
public boolean isFull()
{
if(rear==max)
{
System.out.println("Rear"+rear+" Max \t"+max);
return true;
}
else
return false;
}
public void display()
{
System.out.println("Elements are");
for(int i=front;i
{
System.out.print("\t"+a[i]);
}
System.out.println("");
}
}
No comments:
Post a Comment