pascal 快排查错

来源:百度知道 编辑:UC知道 时间:2024/05/29 03:23:55
program quicksort(input,output);
const
inf='quicksort.in';
outf='quicksort.out';
max=10000;
type
qqq=array[0..max] of integer;
var
i,j,k,n:integer;
a:qqq;
procedure quicksort(var a:qqq;lift,right:integer);
var
i,j,k:integer;
begin
if lift>=right then exit;
i:=lift;
j:=right;
a[0]:=a[i];
while i<j do
begin
while(a[j]>=a[0]) and (i>j) do
dec(j);
a[i]:=a[j];
end;
a[i]:=a[0];
quicksort(a,i,j-1);
quicksort(a,i+1,j);
end;

begin
assign(input,inf);
reset(input);
assign(output,outf);
rewrite(output);
readln(input,n);
for i:=1 to n do
begin
read(input,a[i]);
end;
writeln(output);
quicksort(a,1,n);
for i:=1 to n do

program Quicksort;
const
maxn=1000;
var
a:array[1..maxn] of longint;
n,i:longint;

procedure qsort(s,t:longint);
var i,j,x,tt:longint;
begin
i:=s; j:=t; x:=a[(s+t)div 2];
repeat
while (a[i]<x) do inc(i);
while (a[j]>x) do dec(j);
if i<=j then begin
tt:=a[i]; a[i]:=a[j]; a[j]:=tt;
inc(i); dec(j);
end;
until i>j;
if s<j then qsort(s,j);
if i<t then qsort(i,t);
end;

直接找fp下demo\test(还是text我忘了)里的qsort.pp不就行了?