主题:帮我看一下这冒泡法为什么不能排序?
{p22}
program p4o3;
const
maxn=10;
type
data=array[1..maxn] of integer;
var
a:data;
i,j,t,m:integer;
begin
for i:=1 to maxn do read(a[i]);
for i:=1 to maxn do write(a[i]:3);
writeln;
for i:=1 to maxn-1 do
for j:=1 to maxn-i do
if a[j+1]<a[j] then
begin
t:=a[j];a[j]:=a[j+1];a[j]:=t;
end ;
for i:=1 to maxn do write(a[i]:5);
read(m);
writeln;
end.
帮我看一下这冒泡法为什么不能排序?
我用WATCHES看到数组a不能更改数据
为什么呢?
program p4o3;
const
maxn=10;
type
data=array[1..maxn] of integer;
var
a:data;
i,j,t,m:integer;
begin
for i:=1 to maxn do read(a[i]);
for i:=1 to maxn do write(a[i]:3);
writeln;
for i:=1 to maxn-1 do
for j:=1 to maxn-i do
if a[j+1]<a[j] then
begin
t:=a[j];a[j]:=a[j+1];a[j]:=t;
end ;
for i:=1 to maxn do write(a[i]:5);
read(m);
writeln;
end.
帮我看一下这冒泡法为什么不能排序?
我用WATCHES看到数组a不能更改数据
为什么呢?