优先级队列实现

优先队列

不公平的队列,效率较高

按顺序入队

插入 insert

  // 
  public void insert(long item) {
    int j;
    if (anInt == 0) {
      queArray[anInt++] = item;
    } else {
      for (j = anInt - 1; j >= 0; j--) {
        if (item > queArray[j]) {
          queArray[j + 1] = queArray[j];
        } else {
          break;
        }
      }
      queArray[j + 1] = item;
      anInt++;
    }
  }

移除

public long remove(){
  return queArray[--anInt];
}

打印最小值

public long peekMin(){
 return queArray[nItem-1];
}

是否为空

public boolean isEmpty(){
  return (nItems == 0);
}

是否队列已满

public boolean isFull(){
  return (nItems == maxSize)
}

猜你喜欢

转载自www.cnblogs.com/MagicalFool/p/10171639.html