c++ vector、list 逆序输出
c++ 顺序容器 逆序输出#include<iostream>#include<vector>using namespace std;int main(){int a[11] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};vector<int> vec(a, a+11);//方法1for (vector<int>::ite
·
c++ 顺序容器 逆序输出
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int a[11] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
vector<int> vec(a, a+11);
//方法1
for (vector<int>::iterator it = vec.end(); it != vec.begin();)
{
cout << *(--it) << " ";
}
cout << "\n";
//方法2
for (vector<int>::reverse_iterator it = vec.rbegin(); it != vec.rend(); ++it)
{
cout << *it << " ";
}
system("pause");
}
更多推荐
已为社区贡献1条内容
所有评论(0)