Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions