- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is deque back( ) in C++?
The deque back( ) function is used to reference last element of deque.
Syntax
dequename.back( )
Example
Input Deque − 11 12 13 14 15
Output New Deque − 15
Input Deque − C H O I C E
Output New Deque − E
Approach can be followed
First we declare the deque
Then we print the deque.
Then we define the back( ) function.
By using above approach we can fetch the last element of the deque.
Example
// C++ code to demonstrate the working of deque back( ) function #include<iostream.h> #include<deque.h> Using namespace std; int main( ){ // initializing deque deque<int> deque ={ 14, 15, 16, 17, 18 }; cout<< “ Deque: “; for( auto x = deque.begin( ); x != deque.end( ); ++x) cout<< *x << “ “; // defining the back( ) function cout<< deque.back( ); return 0; }
Output
If we run the above code then it will generate the following output
Input: 14 15 16 17 18 Output: 18 Input: S A L T Output: T
Advertisements