Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var a: array of integer := (20, 18, 7, 4, 5, 14, 6, 1, 12, 9);
- procedure Partition (L,R: integer);
- var
- i, j: integer;
- w, x: integer;
- begin
- if L = R then Exit;
- i := L; j := R;
- x := a[(L + R) div 2 - 1];
- repeat
- while a[i - 1] < x do i := i + 1;
- while a[j - 1] > x do j := j - 1;
- if i <= j then
- begin
- w := a[i - 1]; a[i - 1] := a[j - 1]; a[j - 1] := w;
- i := i + 1; j := j - 1;
- end;
- until i > j;
- if L < j then Partition(L, j);
- if i < R then Partition(i, R);
- end;
- begin
- writeln(a);
- Partition(1, a.Length);
- writeln(a);
- end.
Add Comment
Please, Sign In to add comment