void seq_sort(int base, int n) { int i, j, end_low, start_high; if (n <= 1) return; int pivot = from[base]; j = base; for (i = base; i < base + n; i++) if (from[i] < pivot) to[j++] = from[i]; end_low = j; for (i = base; i < base + n; i++) if (from[i] == pivot) to[j++] = from[i]; start_high = j; for (i = base; i < base + n; i++) if (from[i] > pivot) to[j++] = from[i]; for (i = base; i < base + n; i++) from[i] = to[i]; seq_sort(base, end_low - base); seq_sort(start_high, n - (start_high - base)); #ifndef NDEBUG for (i = base + 1; i < base + n; i++) if (from[i] < from[i - 1]) { fprintf(stderr, "missorted\n"); exit(2); } #endif }
int main() { struct list *data = NULL; seq_read(&data); seq_write(data); __VERIFIER_plot(NULL); // NOTE: you may mix seq_insert/seq_sort as you like, we'll take care of it seq_sort(&data); seq_write(data); __VERIFIER_plot(NULL); seq_destroy(data); __VERIFIER_plot(NULL); return 0; }