Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions