优先队列
#ifndef PRIORITYQUEUE_H #define PRIORITYQUEUE_H template <class T> class PriorityQueue { private: T *x; int size,capacity; void swap(int i,int j) { T t=x[i];x[i]=x[j];x[j]=t; } public: PriorityQueue(int initCapacity) { capacity=initCapacity; x=new int[capacity+1]; size=0; } void enqueue(T t) { x[++size]=t; //heap(1,size-1) int p; for(int i=size;i>1&&x[p=i/2]>x[i];i=p) swap(p,i); //heap(1,size) } T dequeue() { T t=x[1]; x[1]=x[size--]; int c; for(int i=1;(c=2*i)<=size;i=c){ if((c+1)<=size&&x[c+1]<x[c]) c++; if(x[i]<=x[c]) break; swap(c,i); } return t; } int getSize(){ return size; } }; #endif//PRIORITYQUEUE_H