/* a-wada/qsortlib/ccg/qsortap.c Nov. 19, 1999 */ /* Copyright (c) 1999 Akira Wada */ /* <<< Example of QSORTBASE to generate sort subroutine >>> */ /* A template of quick sort for the array of pointers to */ /* an object with large or variable length, etc */ /** define the object to be sorted **/ typedef struct { int nmb; char *grp; double sum; int klg; char text[108];} typeA; /** specify the sorting parameters **/ #include #define QSNAME qsortap #define ARGSP typeA *P[], int N #define SRTWRK typeA *t #define KLG1 16 #define COMPP(i, j) ((cmp = strncmp ( \ P[i]->grp, P[j]->grp, KLG1)) != 0 ? cmp : ( \ P[i]->sum > P[j]->sum ? -1 : ( \ P[i]->sum < P[j]->sum ? 1 : \ P[i] - P[j] ))) /* <- uniquekey for stability */ #define SWAPP(i, j) t = P[i], P[i] = P[j], P[j] = t #define ROTATEP(i, j, k) t = P[i], P[i] = P[j], P[j] = P[k], P[k] = t /** call the sorting algorithm (QSORTBASE) **/ #define ARGS ARGSP typedef int PTRTYP; #define DFWRK STACK; SRTWRK #define VALID N > 1 #define HSKP l = 0, r = N - 1 #define ESZ 1 #define COMP(i, j) COMPP (i, j) #define SWAP(i, j) SWAPP (i, j) #define ROTATE(i, j, k) ROTATEP (i, j, k) #define CLNUP /* nothing */ #define STACK PTRTYP s[STKSZ], *p = s #define STKSZ sizeof (int) * 8 * 2 #define PUSH(x, y) *(p++) = x, *(p++) = y #define EMPTY (s >= p) #define POP(y, x) y = *(--p), x = *(--p) #include "qsortbase.h" QSORTBASE (QSNAME) /* a-wada/qsortlib/ccg/qsortap.c end */