一、定义一个队列类,包含类的构造方法及操作方法。
class ArrQueue{
private int MaxSize;
private int front;
private int rear;
private int[] arr;
public ArrQueue(int arrMaxsize){
MaxSize = arrMaxsize;
arr = new int[arrMaxsize];
front = 0;
rear=0;
}
public boolean IsFull(){
return (rear+1)% MaxSize == front;
}
public boolean IsEmpty(){
return rear==front;
}
public void add(int n){
if (IsFull()){
System.out.println("队列已满不能加入数据!");
return;
}
arr[rear]=n;
rear = (rear+1)%MaxSize;
}
public void printQueue(){
if (IsEmpty()){
System.out.println("队列为空!");
return;
}
for (int i = front; i < front+size()