Data Structure Quick Sort Algorithm

Data Structure Algorithm for  Quick sort  pseudo-code.

After knowing and completely understanding this algorithm for  Quick sort . You will be able to write a Data Structure Program for  Quick sort  in any language. The basic ideology and idea behind all the programs will be same. Yes the programs will differ according to the syntax and semantics of the language. This is a part of  Mumbai University MCA Colleges Data Structure MCA Sem 2

Algorithm QuickSort(list, left, right) (* Assume the list is not empty. *)
1 set pivot to Median(left, right, middle)
2 set sortLeft to left+1
3 set sortRight to right
4 loop sortLeft <= sortRight
1 loop [sortLeft] < [pivot]
1 increment sortLeft
2 end loop
3 loop [sortRight] >= [pivot]
1 decrement sortRight
4 end loop
5 if sortLeft < sortRight
1 exchange( sortLeft, sortRight)
2 increment sortLeft
3 decrement sortRight
6 end if
5 end loop
6 exchange(pivot, sortLeft-1) (* return the pivot into correct location *)
(* start left partition sort *)
7 if left < pivot
1 quickSort(list, left, pivot-1)
8 end if
(* start right partition sort *)
9 if right > pivot
1 quickSort(list, pivot+1, right)
10 end if
End QuickSort

Hope this Algorithm is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

No comments:

Post a Comment