//myListswap1.cpp #include #include #include using namespace std; //list swap function int main() { string str1[] = {"A", "C", "B","D"}; string str2[] = {"E", "F","G","H"}; // list Lstr1(str1, str1+4); list Lstr2(str2, str2+4); // cout<<"\n Lstr1.size() : " << Lstr1.size() <:: iterator it; cout<<"\n Lstr1 Origninal string \n"; for(it= Lstr1.begin(); it !=Lstr1.end(); it++) { cout <<" "<< *it; } cout<<"\n---Lstr2 Orginal string \n"; for(it= Lstr2.begin(); it !=Lstr2.end(); it++) { cout <<" "<< *it; } Lstr2.swap(Lstr1); // copy Lstr1 to Lstr2 after swap cout<<"\n----Lstr1 after swap-------\n"; for(it= Lstr1.begin(); it !=Lstr1.end(); it++) { cout <<" "<< *it; } cout<<"\n---Lstr2 after swap------- \n"; for(it= Lstr2.begin(); it !=Lstr2.end(); it++) { cout <<" "<< *it; } return 0; }