Question
The output of the Sorted is in Ascending. I have been wracking my brain for an hour on how to switch it around and make
The output of the "Sorted" is in Ascending. I have been wracking my brain for an hour on how to switch it around and make it print in "descending". Help is appreciated.
//push 15 random integers in the range 0-99 for (int i = 1; i < 15; i++) v.push_back(rnd.random(100));
cout << "Original:"; writeMiniVector(v);
sortMiniVector(v);
cout << "Sorted:"; writeMiniVector(v);
}
// output miniVector v template void writeMiniVector(const miniVector& v) { for (int i = 0; i < v.size(); i++) cout << " " << v[i];
cout << endl << endl; } // use insertion sort to place miniVector v to place in a descending order template void sortMiniVector(miniVector& v) { int i, j, currentVal; for (i = 1; i < v.size(); i++) { currentVal = v[i]; j = i - 1;
///compare with each previous element and swap if previous is greater than the one before while (j >= 0 && v[j] > currentVal) { v[j + 1] = v[j]; j = j - 1; } v[j + 1] = currentVal; } } //end
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