This contains an example of how to use quicksort_index.
#include <stdlib.h>
#include <stdio.h>
#include "tests.h"
{
#define LEN 128
int a[LEN];
int idx[LEN];
for (int i = 0; i < LEN; ++i) {
a[i] = LEN-i-1;
idx[i] = i;
}
for (int i = 0; i < LEN; ++i) {
printf ("Unsorted list is i=%i a[i]=%i idx[i]=%i\n ", i, a[i], idx[i]);
}
for (int i = 0; i < LEN; ++i) {
if ((i != a[i]) || (idx[i] != LEN-i-1)) INC_ERR;
printf ("Sorted list is i=%i a[i]=%i idx[i]=%i\n ", i, a[i], idx[i]);
}
#undef LEN
}
{
#define LEN 128
int a[LEN];
int idx[LEN];
for (int i = 0; i < LEN; ++i) {
a[i] = i;
idx[i] = i;
}
for (int i = 0; i < LEN; ++i) {
printf ("Unsorted list is i=%i a[i]=%i idx[i]=%i\n ", i, a[i], idx[i]);
}
for (int i = 0; i < LEN; ++i) {
if ((i != a[i]) || (idx[i] != i)) INC_ERR;
printf ("Sorted list is i=%i a[i]=%i idx[i]=%i\n ", i, a[i], idx[i]);
}
#undef LEN
}
return TEST_EXIT_CODE;
}
int main(int argc, char **argv)
void yac_quicksort_index(int *a, size_t n, int *idx)