Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

I need the sorted list to print largest to smallest. It's currently printing smallest to largest. Thanks

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

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

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions