For small numbers of sorting, it could be done pretty easily this way:
Code:
inline int sortrowsCompareFcn(const void * a,const void * b, int nSortColumn)
{
double** val1 = (double**) a;
double** val2 = (double**) b;
if(val1[0][nSortColumn] < val2[0][nSortColumn] )
{
return -1;
}
else if(val1[0][nSortColumn] > val2[0][nSortColumn] )
{
return 1;
}
else
{
return 0;
}
}
#define SORTNAME(n) sortrowsCompareFcn##n
#define SORTN(n) int SORTNAME(n)(const void * a,const void * b) { sortrowsCompareFcn(a, b, n); }
SORTN(0)
SORTN(1)
SORTN(2)
SORTN(3)
SORTN(4)
SORTN(5)
SORTN(6)
SORTN(7)
SORTN(8)
SORTN(9)
SORTN(10)
typedef int (*SortFunc)(void *a, void *b);
SortFunc sortFunctions[11] = {
SORTNAME(0),
SORTNAME(1),
SORTNAME(2),
SORTNAME(3),
SORTNAME(4),
SORTNAME(5),
SORTNAME(6),
SORTNAME(7),
SORTNAME(8),
SORTNAME(9),
SORTNAME(10),
}
void sortrows(double** pMatrix,int nStartRow, int nStopRow, int nColumn)
{
qsort((void*) (pMatrix+nStartRow),nStopRow-nStartRow+1,sizeof(double*), sortFunctions[n]);
}
--
Mats