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

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter17: Linked Lists
Section: Chapter Questions
Problem 18PE
icon
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.
steps

Unlock instant AI solutions

Tap the button
to generate a solution

Knowledge Booster
Concept of memory addresses in pointers
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr