Hiển thị kết quả từ 1 đến 6 / 6

Chủ đề: Quick sort

  1. #1
    Tham gia
    23-06-2009
    Location
    Huyện Gia Bình - Tỉnh Bắc Ninh
    Bài viết
    323
    Like
    0
    Thanked 4 Times in 4 Posts

    Quick sort

    Nêu ý tưởng và viết chương trình sắp xếp dãy số nguyên theo kiểu Quick Sort(sắp xếp nhanh)
    Quote Quote

  2. #2
    Tham gia
    14-07-2011
    Bài viết
    179
    Like
    3
    Thanked 83 Times in 68 Posts
    cái này bạn cần hỏi hay đánh đố người khác????????

  3. #3
    Tham gia
    24-02-2008
    Bài viết
    260
    Like
    6
    Thanked 23 Times in 21 Posts

  4. #4
    Tham gia
    23-06-2009
    Location
    Huyện Gia Bình - Tỉnh Bắc Ninh
    Bài viết
    323
    Like
    0
    Thanked 4 Times in 4 Posts
    Code:
    {Sap xep nhanh Quick sort}
     
    type mang=array[1..100] of integer;
    Var A:mang;
    i,N,x:integer;
    procedure phandoan(l,r:integer);
    Var i,j,x,w:integer;
    Begin
    x:=A[(l+r) div 2];
      i:=l;j:=r;
      Repeat
        While(a[i]<x) do i:=i+1;
         While (x<a[j]) do j:=j-1;
          If i<=j then
            Begin
              w:=a[i];a[i]:=a[j];a[j]:=w;
              i:=i+1;j:=j-1;
            End;
     until i>j;
     If l<j then phandoan(l,j);
     If i<r then phandoan(i,r);
    End;
    BEGIN
    write('Nhap vao so phan tu cua mang:');Readln(N);
    For i:=1 to N do
     begin
       write('A[',i,']=');
       Readln(A[i]);
     End;
    phandoan(1,N);
      For i:=1 to N do write(A[i]:3);
     Readln
    End.

  5. #5
    Tham gia
    29-05-2011
    Location
    Hà Nội
    Bài viết
    1,826
    Like
    1,420
    Thanked 47 Times in 42 Posts
    đây là code sắp xếp nhanh trong phần VD của turbo pascal, bạn xem thử nhá:
    Code:
    {************************************************}
    {                                                }
    { QuickSort Demo                                 }
    { Copyright (c) 1985,90 by Borland International }
    {                                                }
    {************************************************}
    
    program QSort;
    {$R-,S-}
    uses Crt;
    
    { This program demonstrates the quicksort algorithm, which      }
    { provides an extremely efficient method of sorting arrays in   }
    { memory. The program generates a list of 1000 random numbers   }
    { between 0 and 29999, and then sorts them using the QUICKSORT  }
    { procedure. Finally, the sorted list is output on the screen.  }
    { Note that stack and range checks are turned off (through the  }
    { compiler directive above) to optimize execution speed.        }
    
    const
      Max = 1000;
    
    type
      List = array[1..Max] of Integer;
    
    var
      Data: List;
      I: Integer;
    
    { QUICKSORT sorts elements in the array A with indices between  }
    { LO and HI (both inclusive). Note that the QUICKSORT proce-    }
    { dure provides only an "interface" to the program. The actual  }
    { processing takes place in the SORT procedure, which executes  }
    { itself recursively.                                           }
    
    procedure QuickSort(var A: List; Lo, Hi: Integer);
    
    procedure Sort(l, r: Integer);
    var
      i, j, x, y: integer;
    begin
      i := l; j := r; x := a[(l+r) DIV 2];
      repeat
        while a[i] < x do i := i + 1;
        while x < a[j] do j := j - 1;
        if i <= j then
        begin
          y := a[i]; a[i] := a[j]; a[j] := y;
          i := i + 1; j := j - 1;
        end;
      until i > j;
      if l < j then Sort(l, j);
      if i < r then Sort(i, r);
    end;
    
    begin {QuickSort};
      Sort(Lo,Hi);
    end;
    
    begin {QSort}
      Write('Now generating 1000 random numbers...');
      Randomize;
      for i := 1 to Max do Data[i] := Random(30000);
      Writeln;
      Write('Now sorting random numbers...');
      QuickSort(Data, 1, Max);
      Writeln;
      for i := 1 to 1000 do Write(Data[i]:8);
    end.

  6. #6
    Tham gia
    19-08-2012
    Bài viết
    24
    Like
    0
    Thanked 2 Times in 2 Posts
    Quote Được gửi bởi Farmer_Boy View Post
    cái này bạn cần hỏi hay đánh đố người khác????????
    Bạn ấy đánh đố người khác thì các Vị mách nước cho bạn đó làm gì!!

Bookmarks

Quy định

  • Bạn không thể tạo chủ đề mới
  • Bạn không thể trả lời bài viết
  • Bạn không thể gửi file đính kèm
  • Bạn không thể sửa bài viết của mình
  •