partitioning - 1 17 9 Another short trip. Perform our swap...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
9 2 11 30 7 24 26 29 12 1 4 17 Above is our initial array. We are going to choose the first element as our pivot. Then, the left reference will be drawn in red and the right reference will be drawn in blue . 17 2 11 30 7 24 26 29 12 1 4 9 We see right away, that we don't have to move the left value, so we start moving the right. 17 2 11 30 7 24 26 29 12 1 4 9 Of course, we stop the right right away, so we perform our swap, and start moving the left again. 4 2 11 30 7 24 26 29 12 1 17 9 4 2 11 30 7 24 26 29 12 1 17 9 We stop the left here and start examining the right. 4 2 11 30 7 24 26 29 12
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 17 9 Another short trip. Perform our swap and start examining the left again. 4 2 1 30 7 24 26 29 12 11 17 9 We stop right away again, and start on the right 4 2 1 30 7 24 26 29 12 11 17 9 4 2 1 30 7 24 26 29 12 11 17 9 4 2 1 30 7 24 26 29 12 11 17 9 4 2 1 30 7 24 26 29 12 11 17 9 The right stops moving here. So, we swap: 4 2 1 7 30 24 26 29 12 11 17 9 Now, there is no more comparisons to make, so we swap the pivot location and where right currently points, and end up with this partitioned array: 4 2 1 7 9 24 26 29 12 11 17 30...
View Full Document

Ask a homework question - tutors are online