-- --Erik Israelsson D1b 871102-1637 "eriis325" --labb3 --Del B with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Ada.Float_Text_IO; use Ada.Float_Text_IO; with Ada.Numerics.Float_Random; with Ada.Numerics.Discrete_Random; procedure Labb3b is --Arrays type Row_Array is array (1 .. 2) of Integer; type Cols_Array is array (1 .. 20) of Row_Array; --RandomGenerator procedure Generate(Columns : out Cols_Array) is subtype One_To_Ten is Integer range 1 .. 10; package One_To_Ten_Random is new Ada.Numerics.Discrete_Random(Result_Subtype => One_To_Ten); G : One_To_Ten_Random.Generator; begin One_To_Ten_Random.Reset(G); for I in 1 .. 2 loop for N in 1 .. 20 loop Columns(N)(I) := One_To_Ten_Random.Random(G); end loop; end loop; end Generate; --Swap procedure Swap(A, B : in out integer) is C : integer; begin C := A; A := B; B := C; end Swap; --Sort procedure Sort(Columns : in out Row_Array) is begin for I in (Columns'First + 1) .. Columns'Last loop for J in reverse I .. Columns'Last loop if Columns(J) < Columns(J -1) then Swap(Columns(J), Columns(J-1)); end if; end loop; end loop; end Sort; Columns : Cols_Array; Row : Row_Array; I1 : Integer := 0; begin Generate(Columns); Put("Unsorted"); New_Line(2); for I in 1 .. 20 loop Put(Columns(I)(1)); Put(Columns(I)(2)); New_Line; end loop; loop Sort(Columns(1..20)(1)); I1 := I1+1; exit when I1 = 20; end loop; Put("Sorted"); New_Line(2); for I in 1 .. 20 loop Put(Columns(I)(1)); Put(Columns(I)(2)); New_Line; end loop; end Labb3b;