function to output values from smallest to largest
write the function template that receives three values and outputs them from the smallest to the largest. Can anyone spot my mistakes ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
template<class T>
void writeInOrder(T val1, T val2, T val3)
{
T min, mid, max;
min=val1;
if(val2<min)
{
mid=min;
min=val2;
}
else
mid=val2;
if(val3>mid)
max=val3;
else
{
max=mid;
if(val3>min)
mid=val3;
else
{
mid=min;
min=val3;
}
}
cout<<endl<<min<<"\t"<<mid<<"\t"<<max;
}
|
Last edited on
I can't see what is wrong.
1) Use a debugger
2) rewrite by using a swap helper function
Topic archived. No new replies allowed.