Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program QuickSort;
- Procedure Partition_Sort(a,t,p,j);
- begin
- i:=t+1;
- j:=p; chot:=a[t];
- Repeat
- while( (a[i]<chot) and (i<=j) ) do
- i:=i+1;
- while((a[i]>chot) and (i<j)) do
- j:=j-1;
- if (i<j) then
- begin
- temp:=a[i]; a[i]:=a[j]; a[j]:=temp;
- i:=i+1;
- j:=j-1;
- end;
- until (i>=j);
- temp:=a[t]; a[t]:=a[j]; a[j]:=temp;
- End;
- Procedure Quick_Sort(a,t,p);
- begin
- if t<p then
- begin
- Partition_Sort(a,t,p,j);
- Quick_sort(a,t,j-1);
- Quick_sort(a,j+1,p);
- end;
- End;
- BEGIN
- Nhập các phần tử ai;
- Quick_Sort(a,1,n);
- In dãy đã sắp xếp;
- readln;
- END.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement