Showing posts with label Queue implementation using Array in Java. Show all posts
Showing posts with label Queue implementation using Array in Java. Show all posts

Sunday, 16 December 2012

Queue implementation using Array in Java


import java.io.*;
class Aray
{
private int a[];
public int c=0,i,front,rear;
public Aray()
{
a=new int[5];
front=0;
rear=-1;
}
public void insert(int val)
{
if(c<=4)
{
rear=(rear+1)%5;
a[rear]=val;
c++;
}
else
System.out.println("Queue is full");
}
public int delete()
{
if(c==0)
{
System.out.println("Queue is Empty");
return 0;
}
else
{
int temp = a[front];
front=(front+1)%5;
c--;
return temp;
}
}
public void display()
{
if(c==0)
{
System.out.println("Queue is Empty");
}
else
{
System.out.println("Elements from front to rear");
int m=0;
for(i=front;m<c;i++,m++)
{
if(i>4)
i=i%5;
System.out.println(a[i]);
}
}
}

}

Best geography books for UPSC prelims, mains

This post is intended to clear the confusion that prevails among the aspirants over how to prepare for UPSC geography and the best books f...