选择排序正确版本
[cpp]#include <iostream>
void swap(int* a, int* b)
{
*a = *a ^ *b;
*b = *a ^ *b;
*a = *a ^ *b;
};
void selectionSort(int* a, int n)
{
int min;
int minIdx;
for (int i = 0; i <= n - 1; i++)
{
min = a[i];
minIdx = i;
for (int j = i + 1; j <= n; j++)
{
if (a[j] < min)
{
min = a[j];
minIdx = j;
}
}
swap(&a[minIdx], &a[i]);
}
};
int main(int argc,char *argv[])
{
int a[10] = {24, 1145, 21, 10, 4, 5, 9, 13, 7, 101};
selectionSort(a, 9);
return 0;
}
补充:软件开发 , C++ ,