Question: Integer vectSize is read from input, then vectSize ints are read and stored in vector tokensToPick. Complete the CreateSequence() recursive case to perform the following

Integer vectSize is read from input, then vectSize ints are read and stored in vector tokensToPick. Complete the CreateSequence() recursive case to perform the following tasks:

Move the element at index i of remainTokens to the end of pickedTokens.

Recursively call CreateSequence().

Move the element from the end of pickedTokens back to index i of remainTokens.

Ex: If the input is 3 7 8 11, then the output is:

All possible sequences: 7:8:11: 7:11:8: 8:7:11: 8:11:7: 11:7:8: 11:8:7: 

Note:

vector.erase(vector.begin() + i) removes the element at index i of vector.

vector.insert(vector.begin() + i, x) insert x into vector at index i.

#include #include using namespace std;

void CreateSequence(vector remainTokens, vector pickedTokens) { unsigned int i; int pick; if (remainTokens.size() == 0) { for (i = 0; i < pickedTokens.size(); ++i) { cout << pickedTokens.at(i) << ':'; } cout << endl; } else { for (i = 0; i < remainTokens.size(); ++i) { pick = remainTokens.at(i); /* Your code goes here */

} } }

int main() { vector tokensToPick(0); vector picks(0); int vectSize; int val; unsigned int i; cin >> vectSize; for (i = 0; i < vectSize; ++i) { cin >> val; tokensToPick.push_back(val); }

cout << "All possible sequences:" << endl; CreateSequence(tokensToPick, picks); return 0; }

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!