All pastes #332881 Raw Edit

Unnamed

public text v1 · immutable
#332881 ·published 2007-01-30 10:39 UTC
rendered paste body
--
--Erik Israelsson D1b 871102-1637 "eriis325"
--labb3
--Del A

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 Labb3 is
   --OneDimensional Array
   type Onedime is
     array (1 .. 20) of Integer;
   I1 : Integer :=0;
   Your_First_Array : Onedime;
   --TwoDimensional Array
   type Twodime is
     array (1 .. 20, 1 .. 2) of Integer;
   Your_Second_Array : Twodime;
   --RandomGenerator
   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;
   --Swap
   procedure Swap(A, B : in out Integer) is
      C : Integer;
   begin
      C := A;
      A := B;
      B := C;
   end Swap;
   --Sort
   procedure Sort(Arr : in out OneDime) is
   begin
      for I in (Arr'First + 1) .. Arr'Last loop
         for J in reverse I .. Arr'Last loop
            if Arr(J) < Arr(J -1) then
               Swap(Arr(J), Arr(J-1));
            end if;
         end loop;
      end loop;
   end Sort;

begin
   One_To_Ten_Random.Reset(G);
   for I in 1 .. 20 loop
      I1 := One_To_Ten_Random.Random(G);
      Your_First_Array(I) := I1;
   end loop;
   Put("Unsorted"); New_Line(2);
   for I in 1 .. 20 loop
      Put(Your_First_Array(I));
      New_Line;
   end loop;
   Sort(Your_First_Array);
   Put("Sorted"); New_Line(2);
   for I in 1 .. 20 loop
      Put(Your_First_Array(I));
      New_Line;
   end loop;


end Labb3;