Pagini recente » Cod sursa (job #883572) | Cod sursa (job #2187031) | Cod sursa (job #2439665) | Cod sursa (job #2216756) | Cod sursa (job #347824)
Cod sursa(job #347824)
1. type vector=array[1..500000] of longint;
2. var a:vector;
3. n,ii,m:longint;
4. f,g:text;
5.
6.
7. procedure Sortare(s,d:longint);
8. VAR i,j,l1,l2:longint;
9. x,z,w:longint;
10. begin
11. i:=s; j:=d; x:=a[(s+d) div 2]; l1:=1; l2:=0 ;
12. repeat
13. while a[i]<x do i:=i+1;
14. while a[j]>x do j:=j-1;
15. if i<=j then begin
16. w:=a[i]; a[i]:=a[j]; a[j]:=w;
17. i:=i+1; j:=j-1
18. end
19. { if a[i]>a[j] then begin
20. w:=a[i]; a[i]:=a[j]; a[j]:=w;
21. z:=l1; l1:=-l2; l2:=-z; i:=i+l1; j:=j+l2;
22. end else
23. begin i:=i+l1; j:=j+l2; end; }
24. until i>j;
25. if s<j then Sortare(s,j);
26. if d>i then Sortare(i,d);
27. end;
28. begin
29. assign(f,'algsort.in'); assign(g,'algsort.out');
30. reset(f); rewrite(g);
31.
32. readln(f,n);
33. for ii:=1 to n do read(f,a[ii]);
34.
35. m:=1;
36. Sortare(m,n);
37.
38. for ii:=1 to n do
39. write(g,a[ii],' ');
40. close(f); close(g);
41.
42. end.