Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

qsort - Sorts the array buffer using Quicksort Algorithm in C

  #include <stdlib.h>
  #include <stdio.h>

  int num[10] = {
    1, 3, 6, 5, 8, 7, 9, 6, 2, 0
  };

  int comp(const void *, const void *);

  int main(void)
  {
    int i;

    printf("Original array: ");
    for(i=0; i<10; i++) printf("%d ", num[i]);

    qsort(num, 10, sizeof(int), comp);

    printf("Sorted array: ");
    for(i=0; i<10; i++) printf("%d ", num[i]);

    return 0;
  }

  /* compare the integers */
  int comp(const void *i, const void *j)
  {
    return *(int *)i - *(int *)j;
  }



Original array: 1 3 6 5 8 7 9 6 2 0
Sorted array: 0 1 2 3 5 6 6 7 8 9