Sort "CodeVS1076"

Source: Internet
Author: User

Description

Give n and n integers, and I hope you'll sort them out from small to large

Input

First line a positive integer n

Second row n spaces separated by a number of integers

Output

Output only one row, from small to large output n spaces separated by integers

Sample Input

3

3 1 2

Sample Output

1 2 3

Hint

1<=n<=100000

Solution

overqualified, heap Template

1Var2 F:Array [1..1000000]OfLongint;3A,i,n,len:longint;45Procedure Swap (VarA,b:longint);6VarX:longint;7Begin8 x:=a;a:=b;b:=X9End;1011ProcedureInsert (A:longint);12Var13X:longint;14Begin(LEN); F[len]:=a; x:=Len16while (x>>1>0)and (f[x>>1]&GT;F[X])Do17BeginSwap (f[x],f[x>>1]); X:=x>>1;19End;20End;21st22functionGet:longint;23Var24X:longint;25Beginget:=f[1]; f[1]:=f[len]; Dec (len); x:=1;27while (x<<1<=len)and ((f[x<<1]&LT;F[X])or (f[x]>f[x<<1 +1]))Do28Begin29if (f[x<<1]<f[x<<1 +1])or (x<<1=Len30ThenBegin Swap (f[x],f[x<<1]);x:=x<<1;End31ElseBegin Swap (f[x],f[x<<1 +1]);x:=x<<1 +1;End;32End;33End;3435Begin36READLN (n);Panax Notoginseng len:=0;38For i:=1to nDo,  begin , read (a);  Insert (a);  The end;   i:=1 to n do write (GET,' );  Writeln;  The end.                   


Seniors wrote the template

1 var2A,h:Array[0..100001] ofLongint;3 I,n,x,t,tmp:longint;4 5 procedureput (x:longint);6 var7 Now:longint;8 begin9Inc (T); H[t]:=x; now:=T;Ten    while(now<>1) and(H[now]1]) Do One     begin ATmp:=h[now]; H[now]:=h[now >>1]; -H[now >>1]:=tmp; Now:=now >>1; -     End; the End; -  - functionGet:longint; - var + Fa,son,now:longint; - begin +get:=h[1]; h[1]:=h[t]; Dec (t); Afa:=1; at    whileFA <<1<=t Do -     begin -       if(FA <<1=T)or(H[fa <<1]&LT;H[FA <<1+1]) -          ThenSON:=FA <<1 ElseSON:=FA <<1+1; -       ifH[SON]&GT;H[FA] ThenBreak ; -TMP:=H[FA]; h[fa]:=H[son]; inh[son]:=tmp; fa:=Son; -     End; to End; +  - begin the READLN (n); *    fori:=1  toN Do $     beginRead (x); Put (x);End;Panax Notoginseng    fori:=1  toN DoWrite (GET,' '); - Writeln; the End.

Sort "CodeVS1076"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.