4个回答
展开全部
程序1:
program kspv;
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;
i:=i+1;j:=j-1;
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.
程序2:
program kspv;
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: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 b[i]:=b[j];i:=i+1;end;
while (b[i]<=x) and (i<j) do i:=i+1;
if i<j then begin b[j]:=b[i];j:=j-1; end
until i=j;
b[i]:=x;
i:=i+1;j:=j-1;
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.
program kspv;
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;
i:=i+1;j:=j-1;
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.
程序2:
program kspv;
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: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 b[i]:=b[j];i:=i+1;end;
while (b[i]<=x) and (i<j) do i:=i+1;
if i<j then begin b[j]:=b[i];j:=j-1; end
until i=j;
b[i]:=x;
i:=i+1;j:=j-1;
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.
展开全部
delphi中的Demos\Threads,这个就是线程+快速排序的例子
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
procedure Sort(l,r:longint);
var i,j,x,y:longint;
begin
i:=l;j:=r;x:=a[(l+r) div 2]; //找到中间数X
repeat //循环把中间数放到正确位置,即左边全部小于X,右边全部大于X
while a[i]>x do i:=i+1; //找到左边一个大于X的数
while x>a[j] do j:=j-1; //找到右边一个小于X的数
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;
var i,j,x,y:longint;
begin
i:=l;j:=r;x:=a[(l+r) div 2]; //找到中间数X
repeat //循环把中间数放到正确位置,即左边全部小于X,右边全部大于X
while a[i]>x do i:=i+1; //找到左边一个大于X的数
while x>a[j] do j:=j-1; //找到右边一个小于X的数
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;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
一、冒泡法排序
FOR I:=1 TO N-1 DO
FOR J:=N DOWNTO I+1 DO
IF A[J]<A[J-1]
THEN BEGIN T:=A[J];
A[J]:=A[J-1];
A[J-1]:=T
END;
二、交换法(最小元素法)排序
FOR I:=1 TO N-1 DO
BEGIN K:=I;
FOR J:=I+1 TO N DO
IF A[K]>A[J]
THEN K:=J;
IF I<>K
THEN BEGIN T:=A[I];
A[I]:=A[K];
A[K]:=T
END
END;
三、插入法排序
FOR I:=2 TO N DO
BEGIN X:=A[I];
J:=I-1;
WHILE (J>0) AND (A[J]>X) DO
BEGIN A[J+1]:=A[J];
J:=J-1
END;
A[J+1]:=X
END;
四、合并法排序
I:=1;
J:=1;
K:=1;
WHILE (I<=M) AND (J<=N) DO
BEGIN IF A[I]<=B[J]
THEN BEGIN C[K]:=A[I];
I:=I+1
END
ELSE BEGIN C[K]:=B[J];
J:=J+1
END;
K:=K+1
END;
WHILE I<=M DO
BEGIN C[K]:=A[I];
I:=I+1;
K:=K+1
END;
WHILE J<=N DO
BEGIN C[K]:=B[J];
J:=J+1;
K:=K+1
END;
五、快速法排序
PROCEDURE QUICKSORT(A,M,N);
BEGIN I:=M;
J:=N;
X:=A[M];
WHILE I<J DO
BEGIN WHILE (A[J]>=X) AND (J>I) DO J:=J-1;
IF J>I
THEN BEGIN A[I]:=A[J];
I:=I+1;
WHILE (A[I]<=X) AND (I<J) DO I:=I+1;
IF I<J THEN BEGIN A[J]:=A[I];
J:=J-1
END
END
END;
A[I]:=X;
IF M<I-1 THEN QUICKSORT(A,M,I-1);
IF J+1<Q THEN QUICKSORT(A,J+1,Q);
FOR I:=1 TO N-1 DO
FOR J:=N DOWNTO I+1 DO
IF A[J]<A[J-1]
THEN BEGIN T:=A[J];
A[J]:=A[J-1];
A[J-1]:=T
END;
二、交换法(最小元素法)排序
FOR I:=1 TO N-1 DO
BEGIN K:=I;
FOR J:=I+1 TO N DO
IF A[K]>A[J]
THEN K:=J;
IF I<>K
THEN BEGIN T:=A[I];
A[I]:=A[K];
A[K]:=T
END
END;
三、插入法排序
FOR I:=2 TO N DO
BEGIN X:=A[I];
J:=I-1;
WHILE (J>0) AND (A[J]>X) DO
BEGIN A[J+1]:=A[J];
J:=J-1
END;
A[J+1]:=X
END;
四、合并法排序
I:=1;
J:=1;
K:=1;
WHILE (I<=M) AND (J<=N) DO
BEGIN IF A[I]<=B[J]
THEN BEGIN C[K]:=A[I];
I:=I+1
END
ELSE BEGIN C[K]:=B[J];
J:=J+1
END;
K:=K+1
END;
WHILE I<=M DO
BEGIN C[K]:=A[I];
I:=I+1;
K:=K+1
END;
WHILE J<=N DO
BEGIN C[K]:=B[J];
J:=J+1;
K:=K+1
END;
五、快速法排序
PROCEDURE QUICKSORT(A,M,N);
BEGIN I:=M;
J:=N;
X:=A[M];
WHILE I<J DO
BEGIN WHILE (A[J]>=X) AND (J>I) DO J:=J-1;
IF J>I
THEN BEGIN A[I]:=A[J];
I:=I+1;
WHILE (A[I]<=X) AND (I<J) DO I:=I+1;
IF I<J THEN BEGIN A[J]:=A[I];
J:=J-1
END
END
END;
A[I]:=X;
IF M<I-1 THEN QUICKSORT(A,M,I-1);
IF J+1<Q THEN QUICKSORT(A,J+1,Q);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询