Simple Data structure for fifo
import java.util.*;
public class Test{
public static int size = 3;
static int[] queueArray = new int[size];
static int top=0;
static int rear = 0;
public static void push(int n)
{
if(top<size)
{
queueArray[top++] = n;
}
else
{
System.out.println("Queue Overflow");
}
}
public static void pop()
{
if (top > rear) {
rear++;
System.out.println("Queue Poped");
}
else
System.out.println("Queue Underflow");
}
public static void isEmpty()
{
if(top == rear)
{
System.out.println("Queue Is Empty");
}
else
{
System.out.println("Queue Is not Empty");
}
}
public static void main(String args[])
{
isEmpty();
push(23);
push(23);
push(23);
push(23);
isEmpty();
pop();
pop();
pop();
pop();
pop();
}
}
0 Comments