1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#include <stdio.h>
void sort(int array[], int size) {
int count_gt = 0;
int count_ls = 0;
int count_eq = 0;
int count = 0;
if(size > 1) {
int temp_gt[size-1];
int temp_ls[size-1];
int temp_eq[size-1];
for(int i=0; i < size; i++) {
if(array[0] < array[i]) temp_gt[count_gt++] = array[i];
if(array[0] > array[i]) temp_ls[count_ls++] = array[i];
if(array[0] == array[i]) temp_eq[count_eq++] = array[i];
}
for(count=0; count < count_ls; count++) array[count] = temp_ls[count];
for(int cnt = 0; cnt < count_eq; cnt++) array[count++] = temp_eq[cnt];
for(int cnt = 0; cnt < count_gt; cnt++) array[count+cnt] = temp_gt[cnt];
sort(&array[0], count_ls);
sort(&array[count], count_gt);
}
}
int main() {
int d[] = {8, 8, 1, 1, 4, 4, 9, 6, 7, 0, 0, 21, 3, 12, 0, 19, 19};
int size = sizeof d / sizeof (int);
sort(d, size);
for(int i=0; i < size; i++) printf(" %d ",d[i]);
printf("\n");
return 0;
}
|