using namespace std;
int main()
{
list<int> l1;
l1.assign(2,3);
list<int>::iterator n = l1.begin();
for(n = l1.begin();n!=l1.end();n++)
{
cout << *n << "\t";
}
cout << endl;
cout << "last one =" << l1.back() <<endl;
cout << "l1.empty =" << l1.empty() <<endl;
cout << endl << "insert" << endl;
l1.insert(l1.begin(),1);
l1.insert(l1.begin(),2);
l1.insert(l1.begin(),2,3);
l1.insert(l1.begin(),4);
for(n = l1.begin();n!=l1.end();n++)
{
cout << *n << "\t";
}
cout << endl << "delete tail" << endl;
l1.pop_back();
for(n = l1.begin();n!=l1.end();n++)
{
cout << *n << "\t";
}
cout << endl << "**********" << endl;
cout << "size =" << l1.size() <<endl;
cout << "front=" << l1.front() <<endl;
cout << "max_size =" << l1.max_size() << endl;
cout << endl << "sort" << endl;
l1.sort();
for(n = l1.begin();n!=l1.end();n++)
{
cout << *n << "\t";
}
cout << endl << "**********" << endl;
cout << endl << "remove" << endl;
l1.remove(3);
for(n = l1.begin();n!=l1.end();n++)
{
cout << *n << "\t";
}
cout << endl << "**********" << endl;
return 0;
}
c++ day8
最新推荐文章于 2024-11-02 14:41:43 发布