本帖最后由 jing397 于 2015-10-7 21:29 编辑
#include <stdio.h>
void swap (int *a, int *b) {
int c = *a;
*a = *b;
*b = c;
}
void selectOrder(int a[],int len){
int min,index;
for (int i = 0; i < len; i++) {
min = a;
index = i;
for (int j = i+1; j < len; j++) {
if(min > a[j]) {
index = j;
min = a[j];
}
}
if (min != a) {
swap(&a[index],&a);
}
}
}
int main(){
int a[6] = {3,1,2,3,4,5};
selectOrder(a, 6);
return 0;
} |
|