发布网友 发布时间:2024-10-24 10:01
共3个回答
热心网友 时间:2024-10-25 03:21
1. 冒泡排序(稳定排序)vara:array[1..10] of integer;n,i,j,t:integer;beginreadln(n);for i:=1 to n doread(a[i]);for i:=1 to n-1 dofor j:=n-1 downto i doif a[j]>a[j+1] then begint:=a[j];a[j]:=a[j+1];a[j+1]:=t;end;for i:=1 to n do write(a[i],' ');writelnend.2. 选择排序(不稳定排序) vara:array[1..10] of integer;n,i,k,j,t:integer;beginreadln(n);for i:=1 to n doread(a[i]);for i:=1 to n-1 do begink:=i;for j:=i+1 to n doif a[k]<a[j] then k:=j;t:=a[k];a[k]:=a[i];a[i]:=t;end;for i:=1 to n do write(a[i],' ');writelnend. 3. 插入排序(稳定排序)vara:array[0..10] of integer;n,i,k,j,t:integer;begina[0]:=-1;readln(n);for i:=1 to n doread(a[i]);for i:=2 to n do begint:=a[i];k:=i-1;while t<a[k] do begina[k+1]:=a[k];dec(k);end;a[k+1]:=t;end;for i:=1 to n dowrite(a[i],' ');writelnend.热心网友 时间:2024-10-25 03:22
不用那么麻烦,最大数才3000,那么就开一个1到3000的数组,读到了加1,然后在跑一遍输出,程序如下:var热心网友 时间:2024-10-25 03:22
冒泡排序: