Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Hoare's Sort

$
0
0
Where am I wrong with the breakdown on the algorithm?
For: 33 6 21 12 19 29 38 22 14 40

... what is the contents of array A after the first pass of Hoare's
version of the Partition method for the Quick Sort?

WHAT I GET: 14 6 21 12 19 29 38 22 33 40
ANSWER: 14 6 21 12 19 29 22 33 38 40

That should be after one pass, how are 38 and 33 swapped?

Logic:
i=start
k=end

move i until i > start
stop at 38 > 33
move k until k < start
stop at 14 < 33
swap
move i until i > start
i = 40 ends first pass

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>