✔ 最佳答案
int number[4] = {89, 68, 5, 12};
int i, j;
int min, temp;
for (i = 0; i < 3; i )
{
min = i;
for (j = i 1; j < 4; j )
{
if (numbers[j] < numbers[min])
min = j;
}
temp = numbers[i];
numbers[i] = numbers[min];
numbers[min] = temp;
for (i = 0; i < 4; i ) cout << numbers[i];
note: < is the less than sign on your keyboard, yahoo cannot display it correctly.
2008-05-01 19:06:35 補充:
Firstly, I don't see how c27742003's answer allows only 3 rounds of swapping. It looks like it needs 4 rounds. Also, this doesn't seem like a selection sort method.
2008-05-01 19:06:44 補充:
Apart from this,
why the argument passing in the swap function is Swap(*int a, *int b)?
shouldn't it be Swap(int* a, int* b) if you means passing by pointers.
2008-05-01 19:06:52 補充:
And when passing the array element into the swap function, an address or the array element was passed in. Then, you call int Temp = a. I think Temp would then be the address of a. And then you assign *b as the address of a by calling *b = Temp?
maybe it should be:
int Temp = *a?
2008-05-01 19:07:00 補充:
Alternatively, it is easier to pass in by reference:
void swap(int &a, int &b)
Please correct me if im wrong.