Evidence of the unusual QuickSort partition scheme

Here is the code I wrote for a medium pivot quicksort for a high school class of AP CS.

it works for some reason. I've also found some versions identical or similar to this one. But I'm not sure it's the same as the Hoare implementation scheme. I tried to analyze it but I found out that it was quite different from the fast sort I knew -> which takes the form of: elements smaller than piv | piv ~ piv | elements greater than piv. But it acts as elements smaller than piv | elements greater than piv. the pivot ends anywhere between the two. but it works. Is it even a quick sort?

``````public static empty midPivAddSwap (int[] a, int start, int end) {
if (start <end) {
int i = start - 1;
int j = end + 1;
int m = start + (end - start) / 2;
int v = a[m];

while (true) {
while[++i] <V);
while (v < a[--j]);

if (i >= j) pause;

swap (a, i, j);
}

middlePivSortV2 (a, start, j);
middlePivSortV2 (a, j + 1, end);
}
}
``````

TL: DR
I have written code for a QuickSort variant. It seems a bit out of the original QuickSort. Can someone tell me why and how it works? + Is it a quicksort?

Posted on