Help please, I need help to implement the combine function for MergeSort, should work for any size vector and the function should combine the elements from vector A and vector B into vector R. supposed to fill in where it says TODO: This is the program: // combines two sorted lists A and B into R // displays comparison every time it is done void combine(vector<int> A, vector<int> B, vector<int> &R) { // TODO: you can find out the size of A using the // TODO: size function. Treat A and B like arrays. cout << "comparison" << endl; // TODO: // be careful -- R comes in as an empty vector with no slots so you have to use push_back } int main() { vector<int> L1; vector<int> L2; vector<int> L3; int N; // how many elements in each of L1 and L2 int e; // for each element cout << "How many elements in each list?" << endl; cin >> N; cout << "List1" << endl; for (int i = 1; i <=N; i++) { cout << "element :"; cin >> e; L1.push_back(e); } cout << "List2" << endl; for (int i = 1; i <=N; i++) { cout << "element :"; cin >> e; L2.push_back(e); } // TODO: call combine here to combine L1 and L2 into L3 cout << "The result is: "; for (int i = 0; i < N*2; i++) { cout << L3[i]; } cout << endl; }// end of main
Help please, I need help to implement the combine function for MergeSort, should work for any size vector and the function should combine the elements from vector A and vector B into vector R. supposed to fill in where it says TODO: This is the program: // combines two sorted lists A and B into R // displays comparison every time it is done void combine(vector<int> A, vector<int> B, vector<int> &R) { // TODO: you can find out the size of A using the // TODO: size function. Treat A and B like arrays. cout << "comparison" << endl; // TODO: // be careful -- R comes in as an empty vector with no slots so you have to use push_back } int main() { vector<int> L1; vector<int> L2; vector<int> L3; int N; // how many elements in each of L1 and L2 int e; // for each element cout << "How many elements in each list?" << endl; cin >> N; cout << "List1" << endl; for (int i = 1; i <=N; i++) { cout << "element :"; cin >> e; L1.push_back(e); } cout << "List2" << endl; for (int i = 1; i <=N; i++) { cout << "element :"; cin >> e; L2.push_back(e); } // TODO: call combine here to combine L1 and L2 into L3 cout << "The result is: "; for (int i = 0; i < N*2; i++) { cout << L3[i]; } cout << endl; }// end of main
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
100%
Help please,
I need help to implement the combine function for MergeSort, should work for any size vector and the function should combine the elements from vector A and vector B into vector R.
supposed to fill in where it says TODO:
This is the program:
// combines two sorted lists A and B into R
// displays comparison every time it is done
void combine(vector<int> A, vector<int> B, vector<int> &R) {
// TODO: you can find out the size of A using the
// TODO: size function. Treat A and B like arrays.
cout << "comparison" << endl;
// TODO:
// be careful -- R comes in as an empty vector with no slots so you have to use push_back
}
int main() {
vector<int> L1;
vector<int> L2;
vector<int> L3;
int N; // how many elements in each of L1 and L2
int e; // for each element
cout << "How many elements in each list?" << endl;
cin >> N;
cout << "List1" << endl;
for (int i = 1; i <=N; i++) {
cout << "element :"; cin >> e;
L1.push_back(e);
}
cout << "List2" << endl;
for (int i = 1; i <=N; i++) {
cout << "element :"; cin >> e;
L2.push_back(e);
}
// TODO: call combine here to combine L1 and L2 into L3
cout << "The result is: ";
for (int i = 0; i < N*2; i++)
{ cout << L3[i]; } cout << endl;
}// end of main
AI-Generated Solution
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
Unlock instant AI solutions
Tap the button
to generate a solution
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education