优先级队列就是学生去食堂排队打饭,同普通队列一样,队头的先打饭,队尾的后打饭,但是这次有人比较厉害,他要插队,你不听他就打你。哎。
package javal.util.test;
public class PriorityQueue {
private int maxSize;
private long[] array;
private int nItems;
public PriorityQueue(int size) {
this.maxSize = size;
this.array = new long[maxSize];
this.nItems = 0 ;
}
//insert
public void insert(long l) {
int x;
if(nItems == 0) {
array[nItems++] = l;
}else {
for( x=nItems -1; x>= 0;x--) {// x 队头下标
if(l < array[x]) {
array[x+1] = array[x];
}else {
break;
}
}
array[x+1] = l;
nItems ++;
}
}
public long get() {
return array[--nItems];
}
public long peek() {
return array[nItems - 1];
}
public boolean isFull() {
return nItems == maxSize;
}
public boolean isEmpty() {
return nItems == 0;
}
public int size() {
retu