Q.) Write a ALGORITHM for the given set of elements using QUICK SORT .
Sol)
# Quicksort(Arr, P, R)
{
if(P<R)
{
q=partition(Arr, P, R)
}
Quicksort(Arr, P, Q)
Quicksort(Arr, Q+1, R)
}
Partition(Arr, P, R)
{
x=Arr[P]
i=p-1
j=r+1
while(TRUE)
{
do
{
j=j-1
}
while(Arr[j]>x)
do
{
i=i+1
}
while(Arr[i]<x)
if(i<j)
{
Exchange(Arr[i],Arr[j])
}
else
{
return j
}
}
No comments:
Post a Comment