Question: ****************Hello I am having trouble with question 5, The part I am having trouble with is my merge funtion, it is the last part of

****************Hello I am having trouble with question 5, The part I am having trouble with is my merge funtion, it is the last part of the lab that I need. I am not sure what Im doing wrong with the for loop for my merge funtion, but my output is not correct. Below is my code so far, and a screenshot of my output. The display of the merge output is "Values of z sorted and merged: " . Thank you in advance.****************************************************

****************Hello I am having trouble with question 5, The part I am

#include

#include /eeded to use vectors.

#include /eeded to use the sort().

using namespace std;

vectorappend(vectora, vector b) // will combine and return the values of vetors a and b. { int n = a.size(); int m = b.size(); vector c(n + m); int i;

for (i = 0; i

for (i = 0; i

return c; }

vector alternate(vector a, vector b) //will alternate and return the values of vectors a and b. { vector c; int i=0;

while(i merge(vector a, vector b) //will sort and return the values of a and b. { vector c; int i=0; for (;ib[i]) { c.push_back(b[i]); } else if(a[i]==b[i]) { c.push_back(a[i]); c.push_back(b[i]); } i++; } if(a.size()

return c; }

int main() { vector x,y,z; //Defines vectors x,y, and z. int temp; cout>temp; while(temp!=-1) //Allows you to store values in vector x. { x.push_back(temp); cin>>temp; } cout>temp; while (temp!=-1) //Allows you to store values in vector y. { y.push_back(temp); cin>>temp; } z=append(x,y); //calls the append funtion. cout

}

having trouble with is my merge funtion, it is the last part

M CSE lab2. jbgarcia79ag 0 (10) Taika Gets An Upgr: D CSE 202 Lab 2 ''O (10) C+ + Array Sort \GCheggStu yl Guided S: XA x x / x #x Ccssusb.edu/kayfese202/lab2.html Apps O YouTube CAS-Calfornia State fFacebaok a Amazancom:Online Online CCompile to alternate elements of vectors ? and o nto a tard vector. If one vector 13 shorter than the other, alternate as long as the shorter vector ten append the remaining elements from the longer vector For example, for the abave vectors a and b, alternate) retus 01 234567 8 9 10 Modify nain) to also call alternate(o the sae two input vectoas. 5. Write fonction vector?int? merge(vector?int> s, vector?nt> b? to merpe two sorted vectors, producing a new sorted vector. To perform this operation, maintain an index into each vector indicating haw much of it has been processed already. Each time, append the smallest unprocessed element and advance its index For example, after sooting the vectors in noinusing sort(a.begin), a.end) sort(o.begin), .end) e and b would look ke 45 78 9 1 0123456 35?? o1 23 andmeree) returns 01 234567 89 10 Modify nain)to call sort)twice, as above, and then call nerg).Yau must include algorithe to use sort) #include 6. Hand in a printout ofyour complcte program and include percen: completed in the ocumentation. Also, hand in a prntout of the typescript of a sample run. 11:27 PM O Type here to search M CSE lab2. jbgarcia79ag 0 (10) Taika Gets An Upgr: D CSE 202 Lab 2 ''O (10) C+ + Array Sort \GCheggStu yl Guided S: XA x x / x #x Ccssusb.edu/kayfese202/lab2.html Apps O YouTube CAS-Calfornia State fFacebaok a Amazancom:Online Online CCompile to alternate elements of vectors ? and o nto a tard vector. If one vector 13 shorter than the other, alternate as long as the shorter vector ten append the remaining elements from the longer vector For example, for the abave vectors a and b, alternate) retus 01 234567 8 9 10 Modify nain) to also call alternate(o the sae two input vectoas. 5. Write fonction vector?int? merge(vector?int> s, vector?nt> b? to merpe two sorted vectors, producing a new sorted vector. To perform this operation, maintain an index into each vector indicating haw much of it has been processed already. Each time, append the smallest unprocessed element and advance its index For example, after sooting the vectors in noinusing sort(a.begin), a.end) sort(o.begin), .end) e and b would look ke 45 78 9 1 0123456 35?? o1 23 andmeree) returns 01 234567 89 10 Modify nain)to call sort)twice, as above, and then call nerg).Yau must include algorithe to use sort) #include 6. Hand in a printout ofyour complcte program and include percen: completed in the ocumentation. Also, hand in a prntout of the typescript of a sample run. 11:27 PM O Type here to search

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!