Jump to content

Quick Sort Algorithm help

Mrcrysis2000
Go to solution Solved by Nineshadow,
function quicksort(array)    if length(array) > 1        pivot := select any element of array        left := first index of array        right := last index of array        while left ≤ right            while array[left] < pivot                left := left + 1            while array[right] > pivot                right := right - 1            if left ≤ right                swap array[left] with array[right]                left := left + 1                right := right - 1        quicksort(array from first index to right)        quicksort(array from left to last index)

In pseudocode. Just implement it in the programming language of your choice.

Pretty much i failed my exam on programming and i need to retake (not my strongest point) and this is one of the questions, 

 

In the language of your choice, show an implementation of the quick sort algorithm. It does not matter if the sort is in-place, returns a new sequence or takes a pointer to an empty list as a parameter. (python) 

 

So if anyone could show me how this is done and what each line is doing i may have a chance

 

Thanks

Link to comment
Share on other sites

Link to post
Share on other sites

function quicksort(array)    if length(array) > 1        pivot := select any element of array        left := first index of array        right := last index of array        while left ≤ right            while array[left] < pivot                left := left + 1            while array[right] > pivot                right := right - 1            if left ≤ right                swap array[left] with array[right]                left := left + 1                right := right - 1        quicksort(array from first index to right)        quicksort(array from left to last index)

In pseudocode. Just implement it in the programming language of your choice.

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×