Warning: include(../mainbanner.htm) [function.include]: failed to open stream: No such file or directory in /home/makedata/public_html/delphitutorial/quicksort.php on line 34

Warning: include(../mainbanner.htm) [function.include]: failed to open stream: No such file or directory in /home/makedata/public_html/delphitutorial/quicksort.php on line 34

Warning: include() [function.include]: Failed opening '../mainbanner.htm' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/makedata/public_html/delphitutorial/quicksort.php on line 34

Warning: include(../left.htm) [function.include]: failed to open stream: No such file or directory in /home/makedata/public_html/delphitutorial/quicksort.php on line 55

Warning: include(../left.htm) [function.include]: failed to open stream: No such file or directory in /home/makedata/public_html/delphitutorial/quicksort.php on line 55

Warning: include() [function.include]: Failed opening '../left.htm' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/makedata/public_html/delphitutorial/quicksort.php on line 55
Delphi Tutorial

Quicksort

Sort the data is process most frequently used in data processing. example like to get the biggest and smallest value. The most efficient of sort method is Quicksort

How do explaine Quicksort works? It take one of elemtens of data is called pivot. Then element in around pivot was rearange. The smaller value than pivot will be placed beside left side and to the larger ones placed on the right side of pivot. When the first process done, the Next process is take a new pivot to sort and rearange the element which have been compiled before. Process will done if the smallest value placed in left side and the lagre value placed in right side. More clear, You can visit the following site::
http://www.cs.auckland.ac.nz/software/AlgAnim/qsort.html
I was get the Quicksort algorithm from:
http://delphi.about.com/od/objectpascalide/a/quicksort.htm

procedure QuickSort(var A: array of Integer;
  iLo, iHi: Integer);
var
Lo, Hi, Pivot, T: Integer; begin Lo:= iLo; Hi:= iHi; Pivot:= A[(Lo + Hi) div 2]; repeat while A[Lo] < Pivot do Inc(Lo); while A[Hi] > Pivot do Dec(Hi); if Lo <= Hi then begin T := A[Lo];
A[Lo] := A[Hi]; A[Hi] := T; Inc(Lo); Dec(Hi) ; end; end; until Lo > Hi; if Hi > iLo then QuickSort(A, iLo, Hi); if Lo < iHi then QuickSort(A, Lo, iHi); end;

To run the sorting process, You need using a array to entry data.

var
 AData : array of longint;

This following procedure shown that result will be displaying in ListBox2 after sorting process finish.

procedure TForm1.BtnSortClick(Sender: TObject);
var
idx : Word;
begin //set the array length SetLength(AData,ListBox1.Items.Count) ; //Entry values into array for idx := 0 to ListBox1.Items.Count - 1 do AData[idx] := StrToInt(ListBox1.Items[idx]); //Do sorting... QuickSort(AData,Low(AData),High(AData)); //Clear the result box ListBox2.Items.Clear;
//Put the sorting result into listbox ProgressBar2.Max:= ListBox1.Items.Count; Progressbar2.Position:= 0; for idx := 0 to ListBox1.Items.Count - 1 do begin Application.ProcessMessages; ProgressBar2.StepIt; ListBox2.Items.Add(IntToStr(AData[idx])); end; end;

This example program also including random data generatorin to test the quick sort.

You can learn more with source code here and executable file.


Warning: include(../ulink468x15.php) [function.include]: failed to open stream: No such file or directory in /home/makedata/public_html/delphitutorial/quicksort.php on line 173

Warning: include(../ulink468x15.php) [function.include]: failed to open stream: No such file or directory in /home/makedata/public_html/delphitutorial/quicksort.php on line 173

Warning: include() [function.include]: Failed opening '../ulink468x15.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/makedata/public_html/delphitutorial/quicksort.php on line 173

Warning: include(../right.htm) [function.include]: failed to open stream: No such file or directory in /home/makedata/public_html/delphitutorial/quicksort.php on line 184

Warning: include(../right.htm) [function.include]: failed to open stream: No such file or directory in /home/makedata/public_html/delphitutorial/quicksort.php on line 184

Warning: include() [function.include]: Failed opening '../right.htm' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/makedata/public_html/delphitutorial/quicksort.php on line 184

Warning: include(../bottombanner.htm) [function.include]: failed to open stream: No such file or directory in /home/makedata/public_html/delphitutorial/quicksort.php on line 199

Warning: include(../bottombanner.htm) [function.include]: failed to open stream: No such file or directory in /home/makedata/public_html/delphitutorial/quicksort.php on line 199

Warning: include() [function.include]: Failed opening '../bottombanner.htm' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/makedata/public_html/delphitutorial/quicksort.php on line 199