sort

const maxn=100000;
type arr=array[0..maxn] of longint;
var a:arr;
    i,n:longint;
procedure swap(var a,b:longint);
var c:longint;
begin
    c:=a; a:=b; b:=c;
end;
procedure sort(l,r:longint;var a:arr);
var i,j,x:longint;
begin
    i:=l; j:=r; x:=a[(i+j) div 2];
    while i<=j do
    begin
        while a[i]<x do inc(i);
        while x<a[j] do dec(j);
        if i<=j then
        begin
            swap(a[i],a[j]);
            inc(i);
            dec(j);
        end;
    end;
    if l<j then sort(l,j,a);
    if i<r then sort(i,r,a);
end;
begin
    readln(n);
    for i:=1 to n do read(a[i]);
    sort(1,n,a);
    for i:=1 to n do write(a[i],' ');
end.

 

posted @ 2015-04-07 20:15  rpSebastian  阅读(144)  评论(0编辑  收藏  举报