pop
语法:
1 |
void pop(); |
pop() 删除第一个元素
源代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
/** * @brief Removes first element. * * This is a typical %queue operation. It shrinks the %queue by one. * The time complexity of the operation depends on the underlying * sequence. * * Note that no data is returned, and if the first element's * data is needed, it should be retrieved before pop() is * called. */ void pop() { __glibcxx_requires_nonempty(); c.pop_front(); } |
测试代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
// 梁笔记 // https://zouzhongliang.com #include <iostream> #include <queue> using namespace std; int main() { queue<int> Qi; Qi.push(1); Qi.push(2); Qi.push(3); Qi.push(4); Qi.push(5); cout<<Qi.size()<<endl; int size = Qi.size(); for(int i=0;i<size;i++){ Qi.pop(); } cout<<Qi.size()<<endl; } |
测试结果
1 2 |
5 0 |