队列的基本运算

#include<queue> 

using namespace std; //这几个头文件必不可少 

int main() 

queue<int>q; //使用前需定义一个queue变量,且定义时已经初始化 

while(!q.empty()) q.pop(); //重复使用时,用这个初始化 

q.push(1); //进队列 

q.pop(); //出队列 

intv=q.front(); //得到队首的值 

ints=q.size(); //得到队列里元素个数 

return 0; 

}

empty()堆栈为空则返回真

pop()移除栈顶元素

push()在栈顶增加元素

size()返回栈中元素数目

top()返回栈顶元素






猜你喜欢

转载自blog.csdn.net/weixin_42324579/article/details/80602547