Implementation of Quick Sort in C++
Write a program and use random data to sort them using Quick
Sort.
The pseudocode for Quick Sort is given as below:
QUICKSORT(A, p, r)
1 if $p < r$
2 $q = PARTITION(A, p, r)$
3 QUICKSORT(A, p, q - 1)
4 QUICKSORT(A, q + 1, r)
To sort an entire array A, the initial call is QUICKSORT(A, 1, A.length).
Partitioning the array
The key to the algorithm is the PARTITION procedure, which rearranges the sub-
array A[p..r] in place.
PARTITION(A, p, r)
1 $x = A[r]$
2 $i = p - 1$
3 for $j = p$ to $r - 1$
4 if $A[j] \le x$
5 $i = i + 1$
6 exchange A[i] with A[j]
7 exchange A[i + 1] with A[r]
8 return i + 1
The above algorithm is already illustrated in the class.
You may like to use the main that has been developed earlier
and used to implement Insertion Sort.
ALL: Remember, all the lab assignments have to be completed
in the lab, not outside, and be submitted,
Must include your code output.