Swap Function. Need Help!

Can anyone help me with what is the correct way to do this assignment?

modify your three-number sort. Instead of comparing each number with the others, change the algorithm:

1.Write a prototype and function called myswap(). It does not return a value, but takes two reference parameters. The function code switches the values of the params, so that param1 has the value originally in param2 and vice versa.

2.compare two numbers in main(), e.g. num1 and num2. If num1 is greater, use the function to swap the numbers, in other words, end up with the value of num1 in num2 and the value of num2 in num1. Now you have an ordered pair.

3.Compare the third number with the smaller of the pair. If it is smaller or equal, output all three in ascending order.

4.If it is larger, compare it with the larger of the two and output all three in ascending order.
Last edited on
1
2
3
4
5
6
template<typename T> void myswap(T& val1, T& val2)
{
    T temp = val1;
    val1 = val2;
    val2 = temp;
}
Topic archived. No new replies allowed.