pascal-的排序整理
冒泡排序:Program ;
Const
infile = 'sort.in';
outfile = 'sort.out';
Var
a: Array[1..100000] of Longint; f:Boolean;i,n,u:Longint;
Begin
Assign(input,infile);
Assign(output,outfile);
Reset(input);
Rewrite(output);
ReadLn(n);
For i := 1 To n Do Read(a[i]);
Repeat
f := true;
For i := 1 To n-1 Do
If a[i] > a[i+1]Then Begin
u:=a[i];a[i]:= a[i+1];a[i+1]:=u;f:=false;
End;
Until f=true;
While a[j]>x Do Dec(j);
If i <= j Then Begin
e := a[i];a[i]:=a[j];a[j]:=e;Inc(i);Dec(j);
End;
until i >j;
If l < j Then quicksort(l,j);
If r > i Then quicksort(i,r);
End;
Begin
Assign(input,infile);
Assign(output,outfile);
Reset(input);
Rewrite(output);
ReadLn(n);
For i := 1 To n Do Read(a[i]);
quicksort(1,n);
For i := 1 To n Do Write(a[i],' ');
Close(input);
Close(output);
End.
希尔排序Program ;
Const
infile = 'sort.in';
outfile = 'sort.out' ;
Var
a:Array[1..1000000] of Integer;t:Boolean; n,jump,i,e:Integer;
Begin
Assign(input,infile);
Assign(output,outfile);
Reset(input);
Rewrite(output);
ReadLn(N);
For i := 1 To n Do Read(a[i]);
jump := n;
While jump > 1 Do Begin
jump:=jump div 2;
Repeat
t:= true;
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论