// my_merge.cc main function to test students my_merge.h // // merge two STL lists (of the same type) to create a third list // that has L1(1), L2(1), L1(2), L2(2), L1(3), L2(3), ... leftovers // #include #include #include using namespace std; #include "my_merge.h" // written by CMSC 109 student and submitted static void put_list(char *name, list L) // local for printing lists { cout << name << " "; list::iterator p = L.begin(); while( p != L.end() ) { cout << *p << " "; // cout operator << must be visible for type *p p++; } cout << endl; } static void put_vector(char *name, vector L) // local printing vectors { cout << name << " "; vector::iterator p = L.begin(); while( p != L.end() ) { cout << *p << " "; // cout operator << must be visible for type *p p++; } cout << endl; } int main() // test program for my_merge.h { list L1; list L2; list L3; // test data L1.push_back(1); L1.push_back(3); L1.push_back(5); L2.push_back(2); L2.push_back(4); L2.push_back(6); L2.push_back(7); put_list("L1", L1); put_list("L2", L2); // test template in my_merge.h on list my_merge(L1.begin(), L1.end(), L2.begin(), L2.end(), L3); put_list("L3", L3); cout << endl; // more test data vector V1; vector V2; vector V3; V1.push_back(1.1); V1.push_back(3.3); V1.push_back(5.5); V1.push_back(6.6); V2.push_back(2.2); V2.push_back(4.4); put_vector("V1", V1); put_vector("V2", V2); // test template in my_merge.h on vector my_merge(V1.begin(), V1.end(), V2.begin(), V2.end(), V3); put_vector("V3", V3); return 0; }