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:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.