Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179
Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /var/www/cppe.ru/www/includes/parser/Preprocessor_DOM.php on line 803
Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179
Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/vendor/mediawiki/at-ease/src/Functions.php on line 48
Материал из C\C++ эксперт
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Use a reverse_iterator to go from the end to the beginning
#include <iostream>
#include <list>
#include <algorithm>
#include <string>
using namespace std;
static const int ARRAY_SIZE = 5;
int main( ) {
list<string> lstStr;
lstStr.push_back("A");
lstStr.push_back("B");
lstStr.push_back("C");
lstStr.push_back("D");
for (list<string>::iterator p = lstStr.begin( );
p != lstStr.end( ); ++p) {
cout << *p << endl;
}
for (list<string>::reverse_iterator p = lstStr.rbegin( );
p != lstStr.rend( ); ++p) {
cout << *p << endl;
}
}
/*
A
B
C
D
D
C
B
A
*/