Advertisement
sapitando

Bubble sort em Pascal 2.

Jul 31st, 2016
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.67 KB | None | 0 0
  1. program Bubble_sort;
  2. uses crt;
  3.  
  4. const MAXNRO = 10;
  5.  
  6. var Nro : array [1..MAXNRO] of extended;
  7.     NroAux : extended;
  8.     C1, C2 : word;
  9.  
  10. begin
  11. Nro[1] := 10;
  12. Nro[2] := 5;
  13. Nro[3] := 3;
  14. Nro[4] := 1;
  15. Nro[5] := 4;
  16. Nro[6] := 9;
  17. Nro[7] := 8;
  18. Nro[8] := 2;
  19. Nro[9] := 7;
  20. Nro[10] := 1;
  21.  
  22. for C1 := 2 to MAXNRO do
  23.  if Nro[C1 - 1] > Nro[C1]
  24.  then begin
  25.        C2 := C1;
  26.        while (C2 > 1) and (Nro[C2 - 1] > Nro[C2]) do
  27.         begin
  28.          NroAux := Nro[C2 - 1];
  29.          Nro[C2 - 1] := Nro[C2];
  30.          Nro[C2] := NroAux;
  31.          dec(C2);
  32.         end;
  33.        end;
  34.  
  35. clrscr;
  36. for C1 := 1 to MAXNRO do
  37.  writeln(C1 : 3,' : ',Nro[C1] : 2 : 2);
  38. readkey;
  39.  
  40. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement