Mega Code Archive

 
Categories / Delphi / Algorithm Math
 

Quick Sort

Title: Quick Sort Question: How to quick sort an array? Answer: This came from the TThread demo of Delphi Modify it for your code...i think it can be very helpfull, it's very fast! if it's reposrt say it to me i'll remove it...please gimme some COMMENT, it's my first submit :P to be less lost go see the demo.. sorry for my bad english :P procedure Sort(var A: array of Integer); procedure QuickSort(var A: array of Integer; iLo, iHi: Integer); var Lo, Hi, Mid, T: Integer; begin Lo := iLo; Hi := iHi; Mid := A[(Lo + Hi) div 2]; repeat while A[Lo] while A[Hi] Mid do Dec(Hi); if Lo begin T := A[Lo]; A[Lo] := A[Hi]; A[Hi] := T; Inc(Lo); Dec(Hi); end; until Lo Hi; if Hi iLo then QuickSort(A, iLo, Hi); if Lo if Terminated then Exit; end; begin QuickSort(A, Low(A), High(A)); end;