Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public class NonZeroNumQueue{ private int[] data; private int total; private int

ID: 3711617 • Letter: P

Question

public class NonZeroNumQueue{
private int[] data;
private int total;
private int front;
private int tail;
public NonZeroNumQueue(){
data=new int[10];
total=0;
front=tail=0;
}
public void enqueue(int num){
//Implement this method here
}
public void dequeue(){
if(!isEmpty()){
total--;
front = (front+1) %data.length;
}
}
public int peek(){
if(isEmpty())
return 0; //0 means the queue is empty
return data[front];
}
public boolean isEmpty(){
return total==0;
}
public boolean isFull(){
return false;
}
public int size(){
return total;
}
}

Explanation / Answer

Following is the java code: