
【C++】STL-priority_queue优先队列非法取数的问题 100
不多说,上个代码:#include<queue>#include<stdio.h>usingnamespacestd;intmain(){priority_queue<i...
不多说,上个代码:
#include<queue>
#include<stdio.h>
using namespace std;
int main()
{
priority_queue<int>q;
q.push(1);
q.push(2);
q.push(3);//至此队列中元素:3 2 1
q.pop();
q.pop();
q.pop();//注意,pop三次,队已经空了
printf("%d\n",q.top());
}
结果,输出1。
求解释!!!明明已经空了,能运行就很奇怪了,居然还不是乱码。
使用的编译器:GNU GCC 4.7.1 展开
#include<queue>
#include<stdio.h>
using namespace std;
int main()
{
priority_queue<int>q;
q.push(1);
q.push(2);
q.push(3);//至此队列中元素:3 2 1
q.pop();
q.pop();
q.pop();//注意,pop三次,队已经空了
printf("%d\n",q.top());
}
结果,输出1。
求解释!!!明明已经空了,能运行就很奇怪了,居然还不是乱码。
使用的编译器:GNU GCC 4.7.1 展开
1个回答
展开全部
你用的什么编译器?我在VC下面执行的话遇到printf("%d\n",q.top());程序直接崩溃了
追问
GNU GCC 4.7.1
上面提了=_=
追答
编译器有bug吧,VC崩溃的行为是正常的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询