public class Queue { public static void main(String[] args) { } public int[] arr; int count=0; int top=0; int size=4; int queue[]=new int[size]; Queue(int size) { arr=new int[size]; } void enqueue(int val) { if(count==arr.length) { System.out.println("Queue is full"); }else { arr[count]=val; count++; } } int dequeue() { if(count==0) { System.out.print("stack is empty"); return -1; } else { count--; return arr[top++]; } } int peek() { if(count==0) { System.out.print("queue is empty"); return -1; } return arr[count-1]; } public boolean isempty() { if(count==0) { System.out.println("Queue is empty"); return true; } return false; } public void display() { for (int i = 0; i < queue.length; i++) { System.out.println("Queue [" + i + "] " + queue[i]); } } } (I need the algorithm of this code)
public class Queue {
public static void main(String[] args) {
}
public int[] arr;
int count=0;
int top=0;
int size=4;
int queue[]=new int[size];
Queue(int size)
{
arr=new int[size];
}
void enqueue(int val)
{
if(count==arr.length)
{
System.out.println("Queue is full");
}else
{
arr[count]=val;
count++;
}
}
int dequeue()
{
if(count==0)
{
System.out.print("stack is empty");
return -1;
}
else
{
count--;
return arr[top++];
}
}
int peek()
{
if(count==0)
{
System.out.print("queue is empty");
return -1;
}
return arr[count-1];
}
public boolean isempty()
{
if(count==0)
{
System.out.println("Queue is empty");
return true;
}
return false;
}
public void display()
{
for (int i = 0; i < queue.length; i++) {
System.out.println("Queue [" + i + "] " + queue[i]);
}
}
}
(I need the
Step by step
Solved in 3 steps with 3 images