how to declare your own function and function pointer to be used with qsort( ) : Sort « Development « C++ Tutorial






#include <iostream>
#include <stdlib.h>
using namespace std;

#define IMAXVALUES 10

int icompare_funct(const void *iresult_a, const void *iresult_b);
int (*ifunct_ptr)(const void *,const void *);

int main( )
{
 int i;
 int iarray[IMAXVALUES]={0,5,3,2,8,7,9,1,4,6};

 ifunct_ptr=icompare_funct;
 qsort(iarray,IMAXVALUES,sizeof(int),ifunct_ptr);
 for(i = 0; i < IMAXVALUES; i++)
   cout <<"[{||}]" << iarray[i];
}

int icompare_funct(const void *iresult_a, const void *iresult_b)
{
 return((*(int *)iresult_a) - (*(int *)iresult_b));
}








5.22.Sort
5.22.1.A Bubble sort
5.22.2.A recursive version of Quicksort for sorting characters
5.22.3.Quick Sort
5.22.4.how to declare your own function and function pointer to be used with qsort( )
5.22.5.Sort Tracer
5.22.6.Selection Sort