Sort the list using quick sort with the middle element as pivot. Show the state of the list after each call to the partition procedure.

Pivot = 5
Smallindex = i
Index = j ⇒ j ≤ 5 (pivot)


11 8 9 4 2 5 3 12 6 10 7 - Move pivot to position 0

5 8 9 4 2 11 3 12 6 10 7 - i (position 1 = 8) - j (position 6 = 3) ⇒ swap 8 and 3

5 3 9 4 2 11 8 12 6 10 7 - i (position 2 = 9) - j (position 4 = 2) ⇒ swap 9 and 2

5 3 2 4 9 11 8 12 6 10 7 - i (position 3 = 4) – no smaller elements than 5
⇒ swap 5 and 4

4 3 2 5 9 11 8 12 6 10 7 – list after the partition

How do I proceed from here? How do I sort the two sublists?

Recommended Answers

All 2 Replies

Please see this page for more algorithm information: http://en.wikipedia.org/wiki/Quicksort

And if the poster is really clever, they will read the man page for the qsort() function...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.