#include <vector>
#include <string>
#include <iostream>
#include <list>
#include <iterator>
using namespace std
;
bool fun(int a
)
{
return a
>5;
}
int main()
{
list
<int> l1
= {1,2,3,4,5};
list
<int> l2
{1,2,3,4,5};
list
<int> l3
(10,2);
list
<int> l4
(10);
list
<int> l5
(l1
.begin()++,l1
.end()--);
l1
.size();
l1
.empty();
l1
.max_size();
cout
<< "resize前:" << endl
;
for(auto tmp
=l1
.begin(); tmp
!=l1
.end(); tmp
++ )
cout
<< *tmp
<< ",";
cout
<< endl
;
l1
.resize(10);
cout
<< "resize后:" << endl
;
for(auto tmp
=l1
.begin(); tmp
!=l1
.end(); tmp
++ )
cout
<< *tmp
<< ",";
cout
<< endl
;
list
<int>::const_iterator it1
= l1
.cbegin();
list
<int>::reverse_iterator it2
= l1
.rbegin();
list
<int>::const_reverse_iterator it3
= l1
.crbegin();
l1
.push_back(222);
l1
.push_front(333);
l1
.pop_back();
l1
.pop_front();
l1
.emplace_back(222);
l1
.emplace_front(333);
l1
.pop_back();
l1
.pop_front();
cout
<< "++++++++++++++++++++++++++\n";
l1
.front();
l1
.back();
l1
.erase(l1
.begin());
l1
.clear();
l1
.assign(4, 0);
l1
.assign(++l2
.begin(), ++l2
.end());
l1
.swap(l2
);
cout
<< "++++++++++++++++++++++++++\n";
l2
= {222,333,444,555};
l1
.insert(l1
.begin(), 5);
l1
.insert(l1
.begin(), l2
.begin()++, l2
.end()--);
l1
= {3,4,7,8,3,4,0,5,3,6};
l1
.sort();
for(auto tmp
=l1
.begin(); tmp
!=l1
.end(); tmp
++ )
cout
<< *tmp
<< ",";
cout
<< endl
;
cout
<< "merge: 合并" << endl
;
l2
= {33,44,55,66};
l1
.merge(l2
);
for(auto tmp
=l1
.begin(); tmp
!=l1
.end(); tmp
++ )
cout
<< *tmp
<< ",";
cout
<< endl
;
l1
.remove(3);
for(auto tmp
=l1
.begin(); tmp
!=l1
.end(); tmp
++ )
cout
<< *tmp
<< ",";
cout
<< endl
;
l1
= {1,2,3,3,3,3,4,5,3,9};
l1
.unique();
for(auto tmp
=l1
.begin(); tmp
!=l1
.end(); tmp
++ )
cout
<< *tmp
<< ",";
cout
<< endl
;
l1
.splice(l1
.begin(), l2
, l2
.begin(), l2
.end());
l1
.splice(l1
.begin(), l2
);
l1
= {1,2,3,4,5,6,7,8};
l2
= {11,22,33,44};
l1
.splice(l1
.begin(), l2
, --l2
.end());
for(auto tmp
=l1
.begin(); tmp
!=l1
.end(); tmp
++ )
cout
<< *tmp
<< ",";
cout
<< endl
;
l1
= {1,2,3,4,5,6,7,8};
l1
.remove_if(fun
);
for(auto tmp
=l1
.begin(); tmp
!=l1
.end(); tmp
++ )
cout
<< *tmp
<< ",";
cout
<< endl
;
return 0;
}
转载请注明原文地址: https://mac.8miu.com/read-23776.html