C++ Deque end()函数返回一个指向deque的" last-the-last"元素的迭代器。如果双端队列集合为空,则end()函数返回的值与begin()函数相同。
其中,过去最后一个:"过去最后一个"是位于最后一个元素之后的元素,并且不指向任何元素。
iterator end();
它返回一个引用了last-the-last元素的迭代器。
让我们看一个简单的例子
#include <iostream> #include<deque> using namespace std; int main() { deque<int> k={10,20,30,40,50}; deque<int>::iterator itr=k.begin(); while(itr!=k.end()) { cout<<*itr; cout<<" "; ++itr; } return 0; }
输出:
10 20 30 40 50
在此示例中,在while循环中使用end()函数在整个双端队列集合中进行迭代。
链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-deque-end-function.html
来源:LearnFk无涯教程网
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)