Always select the last element in the ‘sub-array’ as a pivot.
Partition the left side and then the right side of the sub-array.
Print out the whole array at the end of every partitioning method.
An array of length 11 or less will be considered sorted, and there is no need to sort or to print them.
Since you cannot just create new sub-arrays for the elements, partition method will need to use another trick to keep track of which elements are greater and which are lower than the pivot.
The In-place Trick
If an element is lower than the pivot, you should swap it with a larger element on the left-side of the sub-array.
Greater elements should remain where they are.
At the end of the partitioning method, the pivot should be swapped with the first element of the right partition, consisting of all larger elements, of the sub-array.
To ensure that you don’t swap a small element with another small element, use an index to keep track of the small elements that have already been swapped into their “place”.
There will be two lines of input:
nn – the size of the array
arar – the nn numbers of the array
Print the entire array on a new line at the end of every partitioning method.
There are no duplicate numbers.
1 3 9 8 2 7 5
1 3 2 5 9 7 8
1 2 3 5 9 7 8
1 2 3 5 7 8 9