Question: Write a function sort3(int& a, int& b, int& c) that swaps its three arguments to arrange them in sorted order. For example, int v =

Write a function sort3(int& a, int& b, int& c) that swaps its three arguments to arrange them in sorted order. For example,

int v = 3; int w = 4; int x = 1; sort3(v, w, x); // v is now 1, w is now 3, x is now 4

Hint: Use sort2 of Exercise P5.14.

Exercise P5.14

Write a function void sort2(int& a, int& b) that swaps the values of a and b if a is greater than b and otherwise leaves a and b unchanged. For example,

int u = 2; int v = 3; int w = 4; int x = 1; sort2(u, v); // u is still 2, v is still 3 sort2(w, x); // w is now 1, x is now 4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!