Quick Sort
By Yin-So Chen

Now that we visit a recursive sorting algorithm. This algorithm involves moving a data, called pivot. The algorithm then partitions the array into two parts by moving the pivot into its correct position, so that items to the pivot's left are smaller then the pivot, and the items to the right are bigger.The algorithm then is called recursively so that it will partition the two subordinate arrays on either side of the pivot until the entire array is sorted.

Below is the pseudo-code of Quick Sort.


Quick Sort (Sorting array A[size])

    While Low is less than High
    {
        Choose Pivot as the element at position A[Low]
        While A[High] is greater than Pivot, decrement High; else move A[High] to A[Low]
        While A[Low] is less than Pivot, increment Low; else move A[Low] to A[High]
    }
    Move Pivot into A[High], see Pivot position as High.
    If Low is less than Pivot point, recursively call Quick Sort with Low =
        Low, High = Pivot point - 1
    If High is greater than Pivot point, recursively call Quick Sort with Low =
        Pivot point + 1, High = High.

Discuss this article in the forums


Date this article was posted to GameDev.net: 9/13/1999
(Note that this date does not necessarily correspond to the date the article was written)

See Also:
Sorting Algorithms

© 1999-2011 Gamedev.net. All rights reserved. Terms of Use Privacy Policy
Comments? Questions? Feedback? Click here!