
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
DEQUE CRBEGIN() in C++
Given the task is to show the working of deque::crbegin() in C++.
Deque is a double ended queue that gives insertion and deletion at each end i.e. front and back with high performance, in contrast to vector that gives high performance insertion at the end i.e. back only.
Also, it provides random access to components too. Though one can insert part in between alternative components in dequeue with insert(), however its performance won't be sensible rather like a vector.
What is deque::crbegin()?
Deque::crbegin(), where crbegin is the constant reverse begin, implies it constantly reverse the begin or in other words it returns the constant_reverse_iterator.
What is a constant iterator?
A constant iterator is not something which is used for modification. It's main purpose is to access them instead. For modifying the elements we use non_const iterators.
Syntax
dequename.crbegin()
Return const_reverse_iterator to reverse from starting −
Returns a const_reverse_iterator inform to the last part within the container (i.e., its reverse beginning).
Return Function −
A const_reverse_iterator to the reverse starting of the sequence.
Member type const_reverse_iterator could be a reverse random access iterator type that points to a const part (see deque member types).
Example
#include <iostream> #include <deque> int main (){ std::deque<int> mydeque = {1,2,3,4,5}; std::cout << "mydeque backwards:"; for (auto rit = mydeque.crbegin(); rit != mydeque.crend(); ++rit) std::cout << ' '<< *rit; std::cout << '\n'; return 0; }
Output
If we run the above program it will generate the following output −
mydeque backwards: 5 4 3 2 1
- Related Questions & Answers
- deque::at() and deque::swap() in C++ STL
- deque::begin() and deque::end in C++ STL
- deque::empty() and deque::size() in C++ STL
- deque::operator= and deque::operator[] in C++ STL
- deque front( ) and deque back( ) in C++ in STL
- Deque emplace_front( ) and deque emplace_back( ) in C++ in STL
- DEQUE CBEGIN() in C++
- deque::at() and deque::swap() in C++ programming STL
- A Deque Class in C#
- deque::push_front() in C++ STL
- Deque shrink_to_fit in C++ STL
- deque push_back( ) in C++ in STL
- Array::crbegin() and array::crend() in C++ STL?
- List crbegin() and crend() function in C++ STL
- Set crbegin() and crend() function in C++ STL