// sorting arrays using QuickSort (qsort)
#include <stdio.h>
#include <stdlib.h>
#define SIZEW 9
#define SIZER 7
// for integers (ascending)
int comp1 (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
// for doubles (descending)
int comp2 (const void * a, const void * b)
{
return ( *(double*)b - *(double*)a );
}
int main (void)
{
int i;
int whole[] = {88, 56, 100, 2, 25, 13, 65, -34, 56};
double real[] = {13.4, -45.32, 123.1, 99.9, -10.1, 0.6, 25.0};
//sorting array of integers
printf("Original array: ");
for (i = 0; i < SIZEW; ++i)
printf("%d ", whole[i]);
qsort(whole, SIZEW, sizeof(int), comp1);
printf("\nSorted array (^): ");
for (i = 0; i < SIZEW; ++i)
printf("%d ", whole[i]);
//sorting array of doubles
printf("\nOriginal array: ");
for (i = 0; i <SIZER; ++i)
printf("%.2lf ", real[i]);
qsort(real, SIZER, sizeof(double), comp2);
printf("\nSorted array (v): ");
for (i = 0; i < SIZER; ++i)
printf("%.2lf ", real[i]);
return (0);