Things you should change:
Sort() is explicitly returning at the end (
return;). The return statement is implicit once you reach the end of a void function, so should not appear.
Pay attention to the spacing between the
= sign. In some places you have
b=c; while in others you have
a = b; Be consistent with the spacing. I suggest the latter, as it seems more readable to me.
You don't have to
return 0 from main. For
main(), the return zero is implicit if not added.
This is also a great opportunity for you to learn about C++ templates. I will suggest you a base implementation that you can study, test, and better understand the awesomeness of this language feature:
void swap_if_greater(T& a, T& b)
if (a > b)
a = b;
b = tmp;
void sort(T& a, T& b, T& c)
Just as in the example provided by @EngieOP, I've added a swap function to reuse more code.
I've also better separated common code by moving the conditional inside the swap function (
swap_if_greater()), since it is common to all inputs.
sort() is now a template function, meaning is can operate on any type, including
char, ... It is a generic function, just as many of the functions in the standard C++ library. This concept promotes great code reuse and low redundancy of functionality.