Skip to content

Problem in QuickSort function #14

Closed

Description

@zxrobin01

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

Activity

  1. added a commit that references this issue on Nov 27, 2025
  2. cristianbuse commented on Nov 27, 2025

    @cristianbuse
    Owner

    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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions