C++ STL 中的 deque_crend
以下是展示 C++ STL 中 Deque crend() 函式功能的任務。
什麼是 Deque?
Deque 是雙端佇列,是一種序列容器,可以在兩端進行擴充套件和收縮操作。佇列資料結構只允許使用者在尾部插入資料,並在頭部刪除資料。讓我們以公交車站的佇列為例,人們只能從佇列的尾部加入,而站在頭部的人是第一個被移除的人,而在雙端佇列中,可以在兩端插入和刪除資料。
deque crend() 函式返回一個 const_reverse_iterator,該迭代器指向 deque 中第一個元素之前的元素,這被認為是反向末尾。
語法
Deque_name.crend( )
返回值
deque_crend() 函式返回 deque 的 const_reverse_iterator。
示例
輸入 Deque - 5 4 3 2 1
輸出 Deque 反向順序 - 1 2 3 4 5
輸入 Deque - 75 45 33 77 12
輸出 Deque 反向順序 - 12 77 33 45 75
可以遵循的方法
首先,我們宣告 deque。
然後,我們列印 deque。
然後,我們使用 crend() 函式。
透過以上方法,我們可以以反向順序列印 deque。
示例
// C++ code to demonstrate the working of deque crend( ) function
#include<iostream.h>
#include<deque.h>
Using namespace std;
int main ( ){
// declaring the deque
Deque<int> deque = { 5, 4, 3, 2, 1 };
// print the deque
cout<< “ Deque: “;
for( auto x = deque.begin( ); x != deque.end( ); ++x)
cout<< *x << “ “;
// printing deque in reverse order
cout<< “ Deque in reverse order:”;
for( auto x = deque.crend( ) - 1; x >= deque.begin( ); --x)
cout<< “ “ <<*x;
return 0;
}輸出
如果我們執行以上程式碼,它將生成以下輸出
Input - Deque: 5 4 3 2 1 Output - Deque in reverse order: 1 2 3 4 5
示例
// C++ code to demonstrate the working of crend( ) function
#include<iostream.h>
#include<deque.h>
Using namespace std;
int main( ){
deque<char> deque ={ ‘L’ , ‘A’ , ‘P’ , ‘T’ , ‘O’ , ‘P’ };
cout<< “ Deque: “;
for( auto x = deque.begin( ); x != deque.end( ); ++x)
cout<< *x << “ “;
// printing deque in reverse order
cout<< “ Deque in reverse order:”;
for( auto x = deque.crend( ) - 1; x >= deque.begin( ); --x)
cout<< “ “ <<*x;
return 0;
}輸出
如果我們執行以上程式碼,它將生成以下輸出
Input – Deque: L A P T O P Output – Deque in reverse order: P O T P A L
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP