The Quick Sort was developed in the early 1960s, by Tony Hoarde, since it became one of the most common sorts. The algorithm performs an in-place comparison sort it utilizes very little extra memory on sorting the string. It has a worst case of O(n^2) and a best case of O(nlogn).
It is first going to select the pivot as the last number in the list
pivot = 58
Then it assigns lo = -1
For each number from 0 to pivot’s position
If a number in that list is less than the pivot number
Then lo is incremented
and it swaps the index number with the number at the lo position
If the number at the end of the list is less than the number at the lo+1 Position
then swap them
Code: step example
41 67 34 0 69 24 78 58
swapping: 41 with 41
41 67 34 0 69 24 78 58
41 67 34 0 69 24 78 58
swapping: 67 with 34
41 34 67 0 69 24 78 58
swapping: 67 with 0
41 34 0 67 69 24 78 58
41 34 0 67 69 24 78 58
swapping: 67 with 24
41 34 0 24 69 67 78 58
41 34 0 24 69 67 78 58
swapping: 69 with 58
41 34 0 24 58 67 78 69
the pivot point is: 58
41 34 0 24 58 67 78 69
41 34 0 24 58 67 78 69
swapping: 41 with 0
0 34 41 24 58 67 78 69
swapping: 34 with 24
0 24 41 34 58 67 78 69
the pivot point is: 24
0 24 41 34 58 67 78 69
swapping: 41 with 34
0 24 34 41 58 67 78 69
the pivot point is: 34
swapping: 67 with 67
0 24 34 41 58 67 78 69
0 24 34 41 58 67 78 69
swapping: 78 with 69
0 24 34 41 58 67 69 78
the pivot point is: 69
0 24 34 41 58 67 69 78
|
#include “iostream” |