package com.example;
/**
* description
*
* @author zhanghaohao089
* @date 2017/8/15
*/
public class Queue {
private int[] array;
private int front;
private int max;
private int count;
private int end;
public Queue(int max) {
this.max = max;
array = new int[max];
front = 0;
end = -1;
}
public boolean isEmpty() {
return count == 0;
}
public boolean isFull() {
return count == max;
}
public void enqueue(int t, boolean pro) {
if (isFull())
throw new IllegalAccessError("IS FULL");
if (++end == max)
end = 0;
array[end] = t;
count ++;
}
public int dequeue() {
if (isEmpty())
throw new NullPointerException("is null");
int value = array[front];
array[front] = -1;
front++;
if (front == max)
front = 0;
count --;
return value;
}
}
用数组实现队列
最新推荐文章于 2020-01-10 22:45:18 发布