#include<iostream>
#include<list>
using namespace std;
int main()
{
int arr[] = { 1,2,3,4,5,6,7,8,9 };
list<int> myList(arr, arr+9);
// 前向iterator
list<int>::iterator it;
cout << "Normal data: \n";
for (it = myList.begin(); it != myList.end(); it++)
{
cout << *it << " ";
}
cout << "\n";
// 反向iterator
list<int> ::reverse_iterator rIt;
cout << "reverse data: \n";
for (rIt = myList.rbegin(); rIt != myList.rend(); rIt++)
{
cout << *rIt << " ";
}
cout << "\n";
return 0;
}
C++ 容器的正向和反向迭代
最新推荐文章于 2024-08-30 10:18:11 发布