三大基本排序专题
Posted KYRIE`RUSSAL
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了三大基本排序专题相关的知识,希望对你有一定的参考价值。
//以下依次是冒泡、选择、插入排序
var n,i:longint;
a:array[0..20] of longint;
procedure BUB;
var i,j,t:longint;
begin
for i:=1 to n-1 do
for j:=1 to n-i do
if a[j]>a[j+1] then begin t:=a[j]; a[j]:=a[j+1]; a[j+1]:=t; end;
end;
procedure SEL;
var i,j,k,t:longint;
begin
for i:=1 to n-1 do
begin
k:=i;
for j:=i+1 to n do
if a[j]<a[k] then k:=j;
t:=a[i]; a[i]:=a[k]; a[k]:=t;
end;
end;
procedure INS;
var i,j,k,t:longint;
begin
a[0]:=-2100000000;
for i:=2 to n do
begin
t:=a[i];
for j:=i-1 downto 0 do
if a[j]>t then a[j+1]:=a[j] else break;
a[j+1]:=t;
end;
end;
begin
readln(n);
for i:=1 to n do read(a[i]);
INS;
for i:=1 to n-1 do write(a[i],\' \');
writeln(a[n]);
end.
a:array[0..20] of longint;
procedure BUB;
var i,j,t:longint;
begin
for i:=1 to n-1 do
for j:=1 to n-i do
if a[j]>a[j+1] then begin t:=a[j]; a[j]:=a[j+1]; a[j+1]:=t; end;
end;
procedure SEL;
var i,j,k,t:longint;
begin
for i:=1 to n-1 do
begin
k:=i;
for j:=i+1 to n do
if a[j]<a[k] then k:=j;
t:=a[i]; a[i]:=a[k]; a[k]:=t;
end;
end;
procedure INS;
var i,j,k,t:longint;
begin
a[0]:=-2100000000;
for i:=2 to n do
begin
t:=a[i];
for j:=i-1 downto 0 do
if a[j]>t then a[j+1]:=a[j] else break;
a[j+1]:=t;
end;
end;
begin
readln(n);
for i:=1 to n do read(a[i]);
INS;
for i:=1 to n-1 do write(a[i],\' \');
writeln(a[n]);
end.
以上是关于三大基本排序专题的主要内容,如果未能解决你的问题,请参考以下文章