Example C Code: Sorting Using Qsort

(C except for console output)
#include <stdlib.h>
#include <iostream>
using namespace std;

int cmp (const void *a, const void *b) {
   if (*(int *)a < *(int *)b) return -1;
   if (*(int *)a > *(int *)b) return 1;
   return 0;
}

int main () {
   int *A = new int[20];
   for (int i=0 ; i < 20 ; i++) A[i] = (rand() % 100);
   for (int i=0 ; i < 20 ; i++) cout << A[i] << " ";
   cout << "\n";

   qsort(A, 20, sizeof(int), cmp);
   for (int i=0 ; i < 20 ; i++) cout << A[i] << " ";
   cout << "\n";
}