You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Their is a mistake in QuickSort function.
You should store the key in the middle to some variable, and compare all key values to the variable but not the key in the arrKeys. The problem will cause dictionary not sort as you expect. And also, you can remove the equal from the comparison to reduce useless swap of keys and values.
Do While newLB < ub
If arrKeys(newLB) >= arrKeys(p) Then Exit Do
newLB = newLB + 1
Loop
Do While newUB > lb
If arrKeys(p) >= arrKeys(newUB) Then Exit Do
newUB = newUB - 1
Loop
You are correct that I forgot to store the pivot / middle variable. Embarrasing mistake 😄
On the equal sign removal, to reduce the useless swaps, we need an additional comparison with the pivot position i.e. if value equal to pivot then also compare the index of the value with the index of the pivot - see b40ce9d
Activity
Fix for #14
cristianbuse commentedon Nov 27, 2025
Hi @zxrobin01
You are correct that I forgot to store the pivot / middle variable. Embarrasing mistake 😄
On the equal sign removal, to reduce the useless swaps, we need an additional comparison with the pivot position i.e. if value equal to pivot then also compare the index of the value with the index of the pivot - see b40ce9d
Thanks a lot!