| Quick Sort: | |||||||
Pseudocode of the partition is given below. |
|||||||
| Algorithm partition (a, p, q) | |||||||
| Step 1: | pivot = a[p]; | ||||||
| Step 2: | i = p-1 ; j=q+1; | ||||||
| Step 3: | while (i<j) | ||||||
| Step 5: | repeat | ||||||
| Step 6: | i = i + 1 |
||||||
| Step 7: | until a[i] >= pivot; | ||||||
| Step 8: | repeat | ||||||
| Step 9: | j = j - 1 |
||||||
| Step 10: | until a[j] <= pivot; | ||||||
| Step 11: | if (i < j) then | ||||||
| Step 12: | swap (a[i], a[j]); | ||||||
| Step 13: | return j | ||||||
Algorithm quick-sort (a, p, q) |
|||||||
| Step 1: | if (p < q) { | ||||||
| Step 2: | mid = partition(a,p,q); | ||||||
| Step 3: | quick-sort (a, p, mid); | ||||||
| Step 4: | quick-sort (a, mid+1, q); | ||||||
| } | |||||||
| Prev | |||||||