English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C++ Deque (Double-Ended Queue)
C ++ The Deque begin() function returns an iterator pointing to the first element of the deque container. If the container is empty, the iterator returned will be equal to end().
iterator begin();
It does not contain any parameters.
It returnsiterator pointing to the first element.
Let's look at a simple example
#include<iostream> #include<deque> using namespace std; int main() { deque<int> n={1,2,3; deque<int>::iterator itr; itr = n.begin(); cout << "first element of the deque:" <<*itr; return 0; }
Output:
first element of the deque:1
In this example, the begin() function returns an iterator to the first element.
Let's look at a simple example
#include<iostream> #include<deque> using namespace std; int main() { deque<char> ch={'C','+','+}; deque<char>::iterator itr; itr=ch.begin()+2; cout<<*itr; return 0; }
In this example, the begin() function increments2Therefore, the begin() function returns an iterator to the third element.