C++ STL 中的 deque_rbegin( )
以下是展示 C++ STL 中 Deque rbegin( ) 函式功能的任務。
什麼是 Deque?
Deque 是雙端佇列,它是一種序列容器,可以在兩端進行擴充套件和收縮。佇列資料結構允許使用者僅在末尾插入資料,並在開頭刪除資料。讓我們以公交車站的佇列為例,人們只能在佇列的末尾加入,而站在佇列最前面的人將第一個被移除。而在雙端佇列中,可以在兩端進行資料插入和刪除。
什麼是 rbegin( ) 函式?
rbegin( ) 函式返回一個反向迭代器,指向 deque 中的最後一個元素,regin( ) 函式反轉 deque。
語法 − deque_name.rbegin( )
返回值 − 它返回一個反向迭代器,指向 deque 的最後一個元素。
示例
輸入 Deque − 10 9 8 7 6 5 4 3 2 1
輸出 反轉後的 Deque − 1 2 3 4 5 6 7 8 9 10
輸入 Deque − G O L D E N
輸出 反轉後的 Deque − N E D L O G
可以遵循的方法
首先,我們宣告 deque。
然後,我們列印 deque。
然後,我們使用 rbegin( ) 函式。
然後,我們列印反轉操作後的新 deque。
透過使用上述方法,我們可以獲得反轉後的 deque
示例
// C++ code to demonstrate the working of deque rbegin( ) function
#include<iostream.h>
#include<deque.h>
Using namespace std;
int main ( ){
// initializing the deque
Deque<int> deque = { 5, 4, 0, 8, 5 };
// print the deque
cout<< “ Deque: “;
for( auto x = deque.begin( ); x != deque.end( ); ++x)
cout<< *x << “ “;
// printing reverse deque
cout<< “ Reversed deque: ”;
for( x = deque.rbegin( ) ; x != deque.rend( ); ++x)
cout<< “ “ <<*x;
return 0;
}輸出
如果我們執行以上程式碼,它將生成以下輸出
Input - Deque: 5 4 0 8 5 Output - Reversed Deque: 5 8 0 4 5
示例
// C++ code to demonstrate the working of deque rbegin( ) function
#include<iostream.h>
#include<deque.h>
Using namespace std;
int main( ){
// initializing deque
deque<char> deque ={ ‘P’ , ‘R’ , ‘O’ , ‘D’ , ‘U’ , ‘C’ , ‘T’ };
cout<< “ Deque: “;
for( auto x = deque.begin( ); x != deque.end( ); ++x)
cout<< *x << “ “;
// printing reversed deque
cout<< “ Reversed deque:”;
for( x = deque.rbegin( ) ; x != deque.rend( ); ++x)
cout<< “ “ <<*x;
return 0;
}輸出
如果我們執行以上程式碼,它將生成以下輸出
Input – Deque: P R O D U C T Output – Reversed deque : T C U D O R P
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP