Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Below is a function that can be used to sort different number in a descending or

ID: 3531769 • Letter: B

Question

Below is a function that can be used to sort different number in a descending order. Thereare120differentpermutationsoffiveunequalvalues,whichwouldmakeittedioustoexhaustivelytestallpossibleinputs.So Whatpre-conditionmustbetruejustbeforeyourlastcalltosortThreetoguaranteeallnumbersaresortedattheend?Whatmustbetruebeforethethirdcalltoguaranteethat?(etc.)

HINT:Feelfreetosimplifyyourassertionswithclaimslikethis:
(A,B)>(C,D,E);thatis,BothAandBaregreaterthanalltherest
Thisismuchsimplerthan(A>C&&A>D&&A>E&&B>C&&B>D&&B>E)


void sortThree(int &first, int &second, int &third)

{

if(first<second)

swap(first, second);

if(first<third)

swap(first, third);

if(second<third)

swap(second, third);

}


void sortFive (a, b, c, d, e)

{

sortThree(a,b,c);

sortThree(a,d,e);

sortThree(b,c,d);

sortThree(c,d,e);

}

Explanation / Answer

http://www.miniwebtool.com/sort-numbers/

http://www.mathworks.in/help/matlab/ref/sort.html

http://www.ehelp.com/questions/10433823/how-to-sort-in-descending-order-after-generating-random-numbers-between-0-99

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote