Posted by: dynamite October 14, 2010
is there anyone who can sort this using quick sort
Login in to Rate this Post:     0       ?        
Grabbing the pseudocode from wikipedia: 

function
quicksort(array)
     
var list less, greater
     
if length(array) 1  
         
return array  
     
select and remove a pivot value pivot from array
     
for each x in array
         
if x pivot then append x to less
         
else append x to greater
     
return concatenate(quicksort(less), pivot, quicksort(greater))

iteration 1
Choose any pivot, for instance, 3 looks good then
(1,1,2,3)  3 (4,5,9,6,5,5)

iteration 2
Chosing 2 as pivot, and 5 as pivot
(1,1) (2) (3) 3 (4,5,5) 5 (6,9)

Third iteration, chosing random pivot as usual
(1) (1) 2 (3) 3 (4,5) 5 5 (6)(9)

Last iteration:
1 1 2 3 3 4 5 5 5 6 9

I hope I am right and I hope it helps. :)



Read Full Discussion Thread for this article