We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
There's the potential for a lot of unnecessary work here. i and pIndex can be exactly the same, making a meaningless swap. More importantly, meaningless swaps can happen if ar[i]>=pivot and ar[i] is already above where pivot will rest after partition is completed.
Ideally i and pIndex should start at opposite ends of the array, and should only swap if i > pivot and pIndex < pivot (assuming i starts at the bottom).
Edit: This still bugs me, but I see this is one of the standard partition methods.
Quicksort 1 - Partition
You are viewing a single comment's thread. Return to all comments →
There's the potential for a lot of unnecessary work here. i and pIndex can be exactly the same, making a meaningless swap. More importantly, meaningless swaps can happen if ar[i]>=pivot and ar[i] is already above where pivot will rest after partition is completed.
Ideally i and pIndex should start at opposite ends of the array, and should only swap if i > pivot and pIndex < pivot (assuming i starts at the bottom).
Edit: This still bugs me, but I see this is one of the standard partition methods.