#include <iostream>
#include <vector>
#include <list>
using namespace std;
void PrintVector(vector<int>);//vector类似数组,用[]可以随机访问元素
void PrintList(list<int>);//list是一个双链表,不支持随机访问,插入和删除效率高
int main()
{
vector<int> vecint;
list<int> _list;
int i=0;
while(i++ < 10)
{
vecint.push_back(i);
_list.push_back(i);
}
PrintVector(vecint);
PrintList(_list);
cout<<vecint[0]<<endl;
return 0;
}
void PrintVector(vector<int> vec)
{
vector<int>::iterator iter = vec.begin();
while(iter != vec.end()) {
cout<<*iter<<" ";
iter++;
}
cout<<endl;
}
void PrintList(list<int> _list)
{
list<int>::iterator iter = _list.begin();
while(iter != _list.end()) {
cout<<*iter<<" ";
iter++;
}
cout<<endl;
}
vector和list
最新推荐文章于 2023-03-11 21:20:25 发布