简单冒泡法
#include <stdio.h>
int main(void){
int num[] = { 5, 6, 7, 3, 1, 2 };
int i = 0;
int j = 0;
int temp = 0;
for (i = 0; i < sizeof(num) / sizeof(num[0]); i++){
printf_s("num[%d] = %d \n", i,num[i]);
}
printf_s("-------\n");
for (i = 0; i < 6; i++){
for (j = 0; j < 5 - i; j++){
if (num[j] > num[j+1]){
temp = num[j];
num[j] = num[j+1];
num[j+1] = temp;
}
}
}
for (i = 0; i < 6; i++){
printf_s("num[%d] = %d \n", i, num[i]);
}
return 0;
}