void qqsort(int *ja, FLOAT *ma, int left, int right){ /*---------------------------------------------------------------------- | | qqsort: sort ja[left]...ja[right] into increasing order | from Kernighan & Ritchie | | ma holds the real values | |---------------------------------------------------------------------*/ int i, last; if (left >= right) return; swapj(ja, left, (left+right)/2); swapm(ma, left, (left+right)/2); last = left; for (i=left+1; i<=right; i++) { if (ja[i] < ja[left]) { swapj(ja, ++last, i); swapm(ma, last, i); } } swapj(ja, left, last); swapm(ma, left, last); qqsort(ja, ma, left, last-1); qqsort(ja, ma, last+1, right); }
Public void sort_idx(VOID_ARG) { Message("Sorting entries..."); idx_dc = 0; idx_gc = 0L; qqsort((char *) idx_key, (int) idx_gt, (int) sizeof(FIELD_PTR), (int (*) (char*, char*))compare); Message("done (%ld comparisons).\n", idx_gc); }
void sort_idx(void) { #ifdef HAVE_SETLOCALE char *prev_locale; #endif MESSAGE("Sorting entries..."); #ifdef HAVE_SETLOCALE prev_locale = setlocale(LC_COLLATE, NULL); setlocale(LC_COLLATE, ""); #endif idx_dc = 0; idx_gc = 0L; qqsort(idx_key, (size_t)idx_gt, sizeof(FIELD_PTR), compare); #ifdef HAVE_SETLOCALE setlocale(LC_COLLATE, prev_locale); #endif MESSAGE1("done (%ld comparisons).\n", idx_gc); }
/* sort input lines */ main(int argc, char *argv[]) { int nlines; int numeric = 0; /* if (argc > 1 && strcmp(argv[1], "-n") == 0) numeric = 1; */ printf("Reading Lines.... Control to readlines...\n"); if ((nlines = readline(lineptr, MAXLINES)) >= 0) { printf("completed readline-calling QSORT\n"); qqsort((void**) lineptr, 0, nlines - 1, (int (*)(void *, void *))strcmp); printf("COmpleted QSORT : Moving to writelines\n"); writeline(lineptr, nlines); return 0; } else { printf("Input too big to sort\n"); return 1; } }