Write an algorithm/pseudo-code to implement QuickSort

Algorithm QuickSort(A[l...r])
//Unsorted list with left and right indices
 p <- A[l] //pivot element
 i <- l
 j <- r+1
 repeat until(i>=j)
  begin
    repeat i <- i+1 until A[i]>=p
    repeat j <= j-1 until A[j]<=p
    Exchange(A[i],A[j])
  end
 Exchange(A[l],A[j])
 QuickSort(A[l...j-1)
 QuickSort(A[j+1...r)
end Algorithm

No comments:

Post a Comment