COUT << a [i] << '';
Cout << Endl;
}
int main ()
{
INT A [] = {4, 3, 9, 3, 7};
Selectionsort (A, 5);
Return 0;
}
Note that the output of this algorithm is now: 0 3 4 7 9
There is no reason for no reason. Only Max in this algorithm uses reference to import parameters, the problem is here,
Please see the specific process, after the maximum value is taken, the array is 4 3 7 3 9
After the maximum value is taken, the array is 4 3 3 7 9
After the third time, the maximum value is taken, the array is 3 3 4 7 9
After the fourth time takes the maximum, the array is 3 3 4 7 9
At this time, two parameters, LHS, RHS point to the same value, that is, are references to A [0].
LHS = LHS RHS; RHS = LHS-RHS; LHS = LHS-RHS; the value of A [0] is 0.
Therefore, when two counts are exchanged, it is best to use a third party to avoid unnecessary errors.