Write a program that takes as input an array of integers and gener- ates a permu
ID: 439968 • Letter: W
Question
Write a program that takes as input an array of integers and gener- ates a permutation that rearranges the input to satisfy the following condition: Let x be the value of the last element of an array A In a new array B, x will be in a position B[i] such that B[j] x for all j < i and B[j] x for j > i. For example, suppose A has the following sequence of integers: 5,2,3,7,6,8,1,4. One among several possible partitions that sat- isfy the above condition is the following one: 3,1,2,4,8,6,7,5. The rightmost element of A, 4, is positioned in the resulting array B so that all elements less than 4 (that is, 1, 2, 3) are to its left (in no particular order), and all elements larger than 4 are to its right (again, in no particular order). Your program should be able to open and read a le named In- putArray that contains a single line of less than 100 inte- gers. Your program will output its permutation on the standard outputExplanation / Answer
#include #include void swap( int & a, int & b) { int x=a; a=b; b=x; } void printVector(std::vector& theVector) { for ( unsigned int i=0; iFactorialVector[i]; int x=inputNumber/currentBase; if (x>i+1) return false ; output[ this->FactorialBaseMinus1-1- i]=x; inputNumber=inputNumber% this->FactorialVector[i]; } output[ this->FactorialBaseMinus1]=0; return true; } FactorialNotation(){ this ->FactorialBase=0;} }; int main() { std::vector theInitialVector, theVector, shorterNotation; FactorialNotation base; theInitialVector.push_back(1); theInitialVector.push_back(2); theInitialVector.push_back(3); theInitialVector.push_back(4); theInitialVector.push_back(5); theInitialVector.push_back(6); base.SetFactorialBase(theInitialVector.size()); theVector=theInitialVector; int x; std::cout > x; std::coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.