/*main.c*/
#include
#include "stdlib.h"
#include "sort.h"
int main(void) {
int number1[] = {3, 5, 1, 6, 9};
sort(number1, 5, larger);
printf("大的在前 ");
int i;
for(i = 0; i < i =" 0;" t =" *a;" a =" *b;" b =" t;"> b;
}
int smaller(int a, int b) {
return a < flag =" 1;" i =" 0;" flag ="="" flag =" 0;" j =" 0;" flag =" 1;" t =" *a;" a =" *b;" b =" t;"> b;
}
int smaller(int a, int b) {
return a < b;
}
void sort(int* arr, int length, CMP compare) {
int flag = 1;
int i, j;
for(i = 0; i < length-1 && flag == 1; i++) {
flag = 0;
for(j = 0; j < length-i-1; j++) {
if(compare(arr[j+1], arr[j])) {
swap(arr + j + 1, arr + j);
flag = 1;
}
}
}
}
沒有留言:
張貼留言