asmodeus94

sortowanie

Feb 14th, 2012
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.91 KB | None | 0 0
  1. program sortowanie;
  2. uses crt;
  3. var
  4. nizej,typLosowania,ify1,ify2,petle1,petle2 : byte;
  5. jeszczeraz : char;
  6. tab : array[1..10]of byte;
  7. tabd : array[1..10]of byte;
  8. procedure losuj;
  9. var x : byte;
  10. begin randomize;
  11. for x:=1 to 10 do begin
  12. tab[x]:=random(10);
  13. tabd[x]:=tab[x]; end;
  14. end;
  15. procedure wyswietl;
  16. var x : byte;
  17. begin
  18. for x:=1 to 10 do begin
  19. gotoxy(x+x,1+nizej);write(tab[x],' ');gotoxy(x+x+35,1+nizej);write(tabd[x],' ');end;
  20. end;
  21. procedure sortowanieBabelkowe;
  22. var x,y,t,schowek : byte;
  23. begin
  24. for y:=1 to 9 do begin
  25.     for x:=1 to 9 do begin
  26.     petle1:=petlee1+1;
  27.     if typLosowania=1 then begin
  28.     if tab[x]>tab[x+1] then begin
  29.     ify1:=ify1+1;
  30.         schowek:=tab[x+1];tab[x+1]:=tab[x];tab[x]:=schowek;
  31.         end;
  32.     end ELSE begin
  33.      if tab[x]<tab[x+1] then begin
  34.      ify1:=ify1+1;
  35.         schowek:=tab[x+1];tab[x+1]:=tab[x];tab[x]:=schowek;
  36.         end;
  37.     end;
  38.     end;
  39.     gotoxy(5,y+5); for t:=1 to 10 do begin write(tab[t]);end;writeln;
  40. end;
  41. end;
  42.  procedure sortuj2;
  43. var
  44.   max,a,schowek,i,t,poz: integer;
  45. begin
  46. i:=1;
  47. poz:=1;
  48. REPEAT
  49. max:=tabd[i];
  50. poz:=i;
  51.     for a:=i to 10 do begin
  52.     petle2:=petle2+1;
  53.         if typLosowania=1 then begin
  54.            if tabd[a]<max then begin
  55.        ify2:=ify2+1;
  56.            max:=tabd[a];
  57.            poz:=a;
  58.            schowek:=tabd[poz];
  59.            tabd[poz]:=tabd[i];
  60.            tabd[i]:=schowek;
  61.            end;
  62.         end ELSE begin
  63.            if tabd[a]>max then begin
  64.        ify2:=ify2+1;
  65.            max:=tabd[a];
  66.            poz:=a;
  67.            schowek:=tabd[poz];
  68.            tabd[poz]:=tabd[i];
  69.            tabd[i]:=schowek;
  70.         end; end;
  71.     end;
  72.   gotoxy(40,5+i); for t:=1 to 10 do begin write(tabd[t]);end;writeln;
  73. i:=i+1;
  74. UNTIL i=10;
  75. end;
  76. begin clrscr; typLosowania:=1;
  77. REPEAT losuj;sortowanieBabelkowe;sortuj2;licznik:=licznik+1;UNTIL licznik=100;
  78. wyswietl;nizej:=1;writeln;
  79. writeln;wyswietl;
  80. readkey;end.
Advertisement
Add Comment
Please, Sign In to add comment