hendigere i

This commit is contained in:
Jan (janneke) Nieuwenhuizen 2022-10-25 15:49:35 +02:00
parent 80956130b8
commit 71f6a0ece1
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
1 changed files with 2 additions and 3 deletions

View File

@ -37,20 +37,19 @@ qpart (char *base, int lo, int hi, size_t size,
int (*compare) (void const *, void const *))
{
char *pivot = base + hi * size;
int i = lo - 1;
int i = lo;
for (int j = lo; j < hi; j++)
{
char *pj = base + j * size;
if (pj != pivot && compare (pj, pivot) < 0)
{
i++;
void *pi = base + i * size;
qswap (pi, pj, size);
i++;
}
}
i++;
char *pi = base + i * size;
qswap (pi, pivot, size);