Menu BAR

FEEL FREE TO ASK ANY PROGRAM and please mention any error if you find it

24 Jan 2013

Algo of QUICK SORT using psuedo-code

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