55 lines
944 B
C++
55 lines
944 B
C++
#include <iostream>
|
|
#include <list>
|
|
using namespace std;
|
|
int main(){
|
|
list<string> a;
|
|
a.push_back("1.Ohyeah");
|
|
a.push_back("2.Ohno");
|
|
std::list<string>::iterator it = a.begin();
|
|
auto ite = a.cbegin();
|
|
cout << *ite << endl;
|
|
a.insert(++it, "0.Ohoh");
|
|
a.push_back("3.Ohhoho");
|
|
for(string x : a){
|
|
cout << x << " ";
|
|
}
|
|
cout << endl;
|
|
|
|
//Copy a to b
|
|
list<string> b(a);
|
|
|
|
auto itmp1 = a.begin();
|
|
itmp1++;
|
|
auto itmp2 = a.end();
|
|
itmp2--;
|
|
a.erase(itmp1, itmp2);
|
|
|
|
for(string x : a){
|
|
cout << x << " ";
|
|
}
|
|
cout << endl << endl;
|
|
//Two Methods going through The Whole List
|
|
auto iit = a.begin();
|
|
for(int i = 0; i < a.size(); i++){
|
|
cout << *iit << " ";
|
|
iit++;
|
|
}
|
|
cout << endl;
|
|
cout << endl;
|
|
|
|
//insert ?
|
|
for(string x : b){
|
|
cout << x << " ";
|
|
}
|
|
cout << endl;
|
|
auto itb = b.begin();
|
|
itb++;itb++;
|
|
b.insert(itb, a.begin(), a.end()); //insert into pos 2
|
|
for(string x : b){
|
|
cout << x << " ";
|
|
}
|
|
cout << endl;
|
|
return 0;
|
|
}
|
|
|