一:前言
这个逆序遍历是将map容器的迭代器进行了变化,reverse_iterator逆向遍历的迭代器 ,它需要 rbegin()和rend()方法指出反向遍历的 起始位置和终止位置。
二:上码演示
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
map<double,double>m;
map<double,double>:: reverse_iterator t; //reverse_iterator逆向遍历的迭代器
// cin >> N;
for(int i = 0; i < 10; i++){
m[i] = i;
}
for(t = m.rbegin(); t != m.rend(); t++){
cout << t->first << ' ' << t->second << endl;
}
}