Advertisement
Guest User

Untitled

a guest
May 19th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.75 KB | None | 0 0
  1. procedure QuickSort(const size: integer; var Comp,Perm: integer; var QA:TArray);
  2. Procedure QuickSort(L,R: Integer);
  3. var
  4.   I,J,X,Y:Integer;
  5. begin
  6.   I:=L;
  7.   J:=R;
  8.   X:=QA[(L+R) div 2];
  9.   repeat
  10.    // if not(QA[I]<X)then
  11.     inc(comp);
  12.     while QA[I]<X do
  13.     begin
  14.       Inc (I);
  15.       inc(comp);
  16.     end;
  17.    // if not(QA[J]>X)then
  18.     inc(comp);
  19.     while QA[J]>X do
  20.     begin
  21.       Dec (J);
  22.       Inc(Comp);
  23.     end;
  24.    // inc(comp);
  25.     if I<=J then
  26.     begin
  27.       SWAP(QA,i,j);
  28.       Inc(Perm);
  29.       Inc (I);
  30.       Dec (J);
  31.     end;
  32.    // inc(comp);
  33.   until I>J;
  34.   //inc(comp);
  35.   if J>L then
  36.     QuickSort(L,J);
  37.    // inc(comp);
  38.   if I<R then
  39.     QuickSort(I,R);
  40. end;
  41. begin
  42.   Comp:= 0;
  43.   Perm :=0;
  44.   QuickSort (0,size);
  45. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement