Question: Given two sorted STL linked lists L1 {0, 2, 3, 5} and L2 {1, 4, 6, 10} merge them together to form a third sorted
| Given two sorted STL linked lists L1 {0, 2, 3, 5} and L2 {1, 4, 6, 10} merge them together | |
| to form a third sorted linked list L3. At the end L3 will contain {0, 1, 2, 3, 4, 5, 6, 10}. | |
| Write the for loop that will do the merge, describe any supporting variables you use. | |
| You may NOT use any algorithm functions from STL (i.e. you may not use anything like list::merge()) | |
| */ | |
| #include | |
| #include | |
| int | |
| main() | |
| { | |
| std::list | |
| std::list | |
| std::list | |
| std::cout << "L1: "; | |
| for(auto itr1 = L1.begin(); itr1 != L1.end(); ++itr1) | |
| std::cout << *itr1 << " "; // 0 2 3 5 | |
| std::cout << std::endl; | |
| std::cout << "L2: "; | |
| for(auto itr2 = L2.begin(); itr2 != L2.end(); ++itr2) | |
| std::cout << *itr2 << " "; // 1 4 6 10 | |
| std::cout << std::endl; | |
| /* Insert your code here YOU MAY NOT USE ANY STL algorithms */ | |
| /* (i.e. you may not use anything like list::merge()) */ | |
| for(auto itr3 = L3.begin(); itr3 != L3.end(); ++itr3) | |
| std::cout << *itr3 << " "; | |
| std::cout << std::endl; | |
| return 0; | |
| }// End of main() |
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
