Q&A

  • 빠른정렬...
다음과 같이 크기가 8인 배열에서

       [123, 34, 189, 56, 150, 12, 9, 240]

빠른정렬(quicksort)을 사용하여
리스트를 정렬하는 알고리즘이 진행되는 과정을 알고 싶은데요..

고수님들의 손길이 필요합니다.  ㅠ.ㅠ
1  COMMENTS
  • Profile
    김병윤 2005.04.14 02:05

    빠른정렬(QuickSort) 입니다.^^
    <!--CodeS-->
    const
      data : array[0..7] of integer = (123,34,189,56,150,12,9,240);

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      sort(0, 7);
    end;

    procedure TForm1.Sort(l, r: Integer);
    var
      i, j, x, y: integer;
    begin
      i := l;
      j := r;
      x := data[(l+r) DIV 2];
      repeat
        while data[i] < x do i := i + 1;
        while x < data[j] do j := j - 1;
        if i <= j then
        begin
          y := data[i];
          data[i] := data[j];
          data[j] := y;
          i := i + 1;
          j := j - 1;
        end;
      until i > j;
        if i < r then Sort(i, r);
        if l < j then Sort(l, j);
    end;
    <!--CodeE-->