优先队列手动实现
int cnt,q[10010];
void push(int x)
{
q[++cnt]=x;
int i=cnt,j=i/2;
while(j!=0&&q[i]<q[j])
{
swap(q[i],q[j]);
i=j;
j=j/2;
}
}
int top()
{
return q[1];
}
void pop()
{
q[1]=q[cnt--];
int i=1,j=i*2;
if(j+1<=cnt&&q[j]>q[j+1])
{
j=j+1;
}
while(j<=cnt&&q[j]<q[i])
{
swap(q[i],q[j]);
i=j;//这里必须写为i=j,因为不知道j是左孩子还是右孩子
j=i*2;
if(j+1<=cnt&&q[j]<q[i])j=j+1;
}
}