Question: Write in C QuickSort using HoarePartition Implement the following algorithm for using Quick Sort to sort an array of elemnts. / / Sorts a subarray

Write in C
QuickSort using HoarePartition
Implement the following algorithm for using Quick Sort to sort an array of elemnts.
//Sorts a subarray by quicksort
//Input: Subarray of array A[0..n 1], of integers defined by its left and right
// indices l and r
//Output: Subarray A[l..r] sorted in nondecreasing order
Quicksort(A[l..r])
if l < r
s HoarePartition(A[l..r])//s is a split position
Quicksort(A[l..s 1])
Quicksort(A[s +1..r])
printSubArray
//Partitions a subarray by Hoares algorithm, using the first element
// as a pivot
//Input: Subarray of array A[0..n 1], defined by its left and right
// indices l and r (l= p
repeat j j 1 until A[j ]<= p
swap(A[i], A[j ])
until i >= j
swap(A[i], A[j ])//undo last swap when i >= j
swap(A[l], A[j ])
return j
Print out the subarray at each step. Enclose the active portion in []. For example:
.QuickSort 345234
[23]3544
233[44]5
233[445]
[233445]
[233445]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!