English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C++ Deque (Double-Ended Queue)
C ++ The cend() function of Deque returns a constant iterator that points to the next position of the last element in the container. The iterator can be incremented or decremented, but cannot modify the content of the deque.
If the container is empty, the content returned by the cend() function is the same as that of the cbegin() function.
const_iterator cend();
It does not take any parameters.
It returns a constant iterator that refers to the next position of the last element in the deque.
Let's look at a simple example when the deque contains character values.
#include <iostream> #include<deque> using namespace std; int main() { deque<char> ch={'j','a','v','a','T','p','o','i','n','t'}; deque<char>::const_iterator itr=ch.cbegin(); while(itr!=ch.cend()) { cout <<*itr; cout << " "; ++itr; } return 0; }
Output:
j a v a T p o i n t
In this example, the cend() function is used to iterate through the entire deque container, and the while loop will continue to execute until and unless 'itr' equals ch.cend().
Let's look at a simple example when the deque contains integer values.
#include <iostream> #include<deque> using namespace std; int main() { deque<int> deq = {100,200,300,400,500}; deque<int>::const_iterator itr = deq.cbegin(); while (itr != deq.cend()) { cout <<*itr; cout << " "; ++itr; } return 0; }
Output:
100 200 300 400 500
In this example, the cend() function is used to iterate through the entire deque container, and the while loop will continue to execute until 'itr' is not equal to deq.cend().