App Inventor for Android is an open-source web application originally provided by Google, and now maintained by the Massachusetts Institute of Technology.
procedureswap(j:longint);//交换 begin a[j]:=a[j] xor a[j+1]; a[j+1]:=a[j] xor a[j+1]; a[j]:=a[j] xor a[j+1]; end; procedurebubblesort;//排序 var i,j:longint; begin for i:=n-1downto1dobegin for j:=1to i dobegin if a[j]>a[j+1] then swap(j); end; end; end;
program qsort; const maxn=99999; var a:array[0..maxn] of longint; time1,time2:longint; n:longint; procedureinput; var i:byte; begin read(n); randomize; for i:=1to n dobegin a[i]:=random(9999); end; end;
procedurequicksort(var a: arrayof integer; l,r:integer); var i,j,x,t:integer; begin i:=l; j:=r; x:=a[(l+r) div2]; repeat while a[i]<x do inc(i); while a[j]>x do dec(j); if i<=j then begin t:=a[i]; a[i]:=a[j]; a[j]:=t; inc(i); dec(j); end; until i>j; if i<r then quicksort(a,i,r); if l<j then quicksort(a,l,j); end;
functioninsert(temp:longint):longint; var flag:boolean; i,j,nn:longint; begin flag:=false; i:=1; j:=n; nn:=(i+j) div2; whilenot flag dobegin if a[nn]<temp thenbegin i:=nn; nn:=(nn+j) div2 end; if a[nn]>temp thenbegin j:=nn; nn:=(nn+i) div2; end; if (nn=i) or (nn=j) thenbegin flag:=true; exit(nn); end; end; end;
procedureoutput; var i:longint; begin for i:=1to n dobegin write(a[i],' '); end; end; procedurework; begin input; time1:=gettime; qsort(a,1,n); time2:=gettime; output; time1:=time1-time2; judge; end; begin work; end.