Question
// Need help with the following c++ code, just need help with filing the code, need code where * appears // Instructions : Void Combine
// Need help with the following c++ code, just need help with filing the code, need code where * appears
// Instructions : Void Combine will take 3 vectors as arguments: A, B and R.
// Combine should work for any size vectors as long as the size of A and B are the same.
// It will combine the elements of A and B into R to produce the sorted list R.
// You should know how to find the size of a vector.
// Display comparison every time an element-element comparison is done.
Your main()
- Will declare three vectors L1, L2 and L3.
- Will ask the user to type integers in increasing order into L1.
- Then ask the user to type more integers in increasing order into L2.
- Then it will call void Combine to combine L1 and L2 to produce L3 which is passed back by reference.
- Display what is in L3.
Required Test Cases: (Must test in this order)Text2.txt
- Combine 1 2 3 with 4 5 6
- Combine 1 3 5 with 2 4 6
- Combine 4 5 6 with 1 2 3
- Combine 1 2 5 6 with 3 4 7 8
// Code
using namespace std;
#include
#include
//--------------------------------------------
//CS311 HW2P2 Combine
//Name: **
//Compiler: g++
//--------------------------------------------
// combine 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 )
{
**
cout << "comparison" << endl;
** // be careful -- R comes in as an empty vector
}
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);}
// 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
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