package arithmetic;
public class PriorityQueue
{
private int maxSize;
private double[] queArray;
private int nItems;
private PriorityQueue(int size){
this.maxSize=size;
this.queArray=new double[maxSize];
this.nItems=0;
}
public void insertPatameter(double para){
if (nItems==0){
queArray[nItems++]=para;
}else if(para<queArray[nItems-1]){
queArray[nItems]=para;
nItems++;
}
else{
for (int j = nItems-1; j >=0; j--)
{
if(para>queArray[j]){
queArray[j+1]=queArray[j];
}else {
break;
}
queArray[j]=para;
}
nItems++;
}
}
public double remove(){
return queArray[--nItems];
}
public boolean isFull(){
return (nItems==maxSize);
}
public boolean isEmpty(){
return (nItems==0);
}
public double peekMin(){
return queArray[nItems-1];
}
/**
* 主函数
*
*/
public static void main(String[] args) throws Exception
{
PriorityQueue priorityQueue=new PriorityQueue(10);
priorityQueue.insertPatameter(10);
priorityQueue.insertPatameter(90);
priorityQueue.insertPatameter(30);
priorityQueue.insertPatameter(50);
priorityQueue.insertPatameter(5);
priorityQueue.insertPatameter(40);
priorityQueue.insertPatameter(80);
priorityQueue.insertPatameter(60);
priorityQueue.insertPatameter(70);
priorityQueue.insertPatameter(2);
while (!priorityQueue.isEmpty()){
System.out.print(" "+priorityQueue.remove());
}
}
}