Advertisement
kator

ada hello world sort array

May 16th, 2019
1,764
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 1.00 KB | None | 0 0
  1. -- plik powinien sie nazywac hello.adb
  2. -- kompilacja: gnatmake <plik>
  3. with Ada.Text_IO; use Ada.Text_IO;
  4.  
  5.  
  6. procedure Hello is
  7.  
  8. type Tablica is array(integer range<>) of Integer;
  9. procedure sort(tab: in out Tablica) is
  10.     shouldEnd: Boolean := false;
  11.     procedure swap(x,y: in out Integer) is t: Integer; begin t := x;x := y;y := t;end;
  12. begin
  13.     while not shouldEnd loop
  14.         shouldEnd := true;
  15.         for i in tab'first .. tab'last -1 loop
  16.             if tab(i) > tab(i+1) then
  17.                 swap(tab(i),tab(i+1));
  18.                 shouldEnd := false;
  19.             end if;
  20.         end loop;
  21.     end loop;
  22. end;
  23.  
  24. shouldEnd: Boolean := false;
  25. tab: Tablica(1..10) := (3,5,1,7,8,4,9,10,2,6);
  26. tab2: array(1..10) of Integer := (3,5,others => 9);
  27. begin
  28.  
  29.     for i in tab'range loop
  30.         Put_line(Integer'image(tab(i)));
  31.     end loop;
  32.    
  33.     Put_line("---- SORTING ----");
  34.     sort(tab);
  35.  
  36.     for i in tab'range loop
  37.         Put_line(Integer'image(tab(i)));
  38.     end loop;
  39.  
  40. end Hello;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement