主题:[讨论]快速排序 请找一下错误
program kspx;
const n=7;
type
arr=array[1..n] of integer;
var
a:arr;
i:integer;
procedure quicksort(var b:arr;s,t:integer);
var i,j,x,t1:integer;
begin
i:=s;j:=t;x:=b[i];
repeat
while (b[j]>=x) and (j>i) do j:=j-1;
if j>i then begin t1:=b[i];b[i]:=b[j];b[j]:=t1;end;
while (b[i]<=x) and (i<j) do i:=i+1;
if i<j then begin t1:=b[j];b[j]:=b[i];b[i]:=t1;end;
until i=j;
b[i]:=x;
if s<j then quicksort (b,s,j);
if i<t then quicksort (b,i,t);
end;
begin
write('input data:');
for i:=1 to n do read(a[i]);
writeln;
quicksort(a,1,n);
write('output data');
for i:=1 to n do write(a[i]:6);
writeln;
end.
这是我看资料上的快速排序,运行不起来
请各位找一下错误
如果有人愿意,请讲解一下
repeat
while (b[j]>=x) and (j>i) do j:=j-1;
if j>i then begin t1:=b[i];b[i]:=b[j];b[j]:=t1;end;
while (b[i]<=x) and (i<j) do i:=i+1;
if i<j then begin t1:=b[j];b[j]:=b[i];b[i]:=t1;end;
until i=j;
这段程序的作用和原理
const n=7;
type
arr=array[1..n] of integer;
var
a:arr;
i:integer;
procedure quicksort(var b:arr;s,t:integer);
var i,j,x,t1:integer;
begin
i:=s;j:=t;x:=b[i];
repeat
while (b[j]>=x) and (j>i) do j:=j-1;
if j>i then begin t1:=b[i];b[i]:=b[j];b[j]:=t1;end;
while (b[i]<=x) and (i<j) do i:=i+1;
if i<j then begin t1:=b[j];b[j]:=b[i];b[i]:=t1;end;
until i=j;
b[i]:=x;
if s<j then quicksort (b,s,j);
if i<t then quicksort (b,i,t);
end;
begin
write('input data:');
for i:=1 to n do read(a[i]);
writeln;
quicksort(a,1,n);
write('output data');
for i:=1 to n do write(a[i]:6);
writeln;
end.
这是我看资料上的快速排序,运行不起来
请各位找一下错误
如果有人愿意,请讲解一下
repeat
while (b[j]>=x) and (j>i) do j:=j-1;
if j>i then begin t1:=b[i];b[i]:=b[j];b[j]:=t1;end;
while (b[i]<=x) and (i<j) do i:=i+1;
if i<j then begin t1:=b[j];b[j]:=b[i];b[i]:=t1;end;
until i=j;
这段程序的作用和原理