第1个回答 推荐于2016-01-09
#include "stdio.h"
void sort(const int, int*);
int main(int argc, char** argv) {
int array[] = {5, 34, 54, 2, 54, 51, 543, 2};
int i = 0;
int arraySize = sizeof(array)/sizeof(array[0]);
sort(arraySize, array);
for (i = 0; i < arraySize; ++ i) {
printf("array[%d] = %d \n",i, array[i]);
}
return 0;
}
//选择排序
void sort(const int size, int* array){
int i, j = 0;
int temp = 0;
for (i = 0; i < size; ++ i) {
for (j = i + 1; j < size; ++ j) {
if (array[i] < array[j]) {
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
}本回答被提问者采纳