Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started