-- This program asks the user to input numbers, and
-- returns the numbers input
-- This program finds the minimum value in an array
-- of integers.
-- Author: John Weber
with Ada.Text_Io, Ada.Integer_Text_Io;
use Ada.Text_Io, Ada.Integer_Text_Io;
-- Ada 95: From The Beginning
-- Chapter 2, Problem 4
procedure Ch2Problem4 is
   type IntegerArray is array(1 .. 100) of Integer;
   Values : IntegerArray;
   Length : Integer := 0;
   Min    : Integer := 0;
   Value  : Integer := 0;
   Before : Integer := 0;
   Index  : Integer := 1;
begin
   -- Make sure I have enough room
   while ( Length < 1 or Length > 100 ) loop
      Put("Please enter the number of values [1-100]: ");
      Get(Length);
   end loop;

   Put("Enter the ");
   Put(Length, WIDTH => 3);
   Put(" values.");
   New_Line;

   -- Run insertion sort as I'm getting numbers
   for L in 1 .. Length loop
      Put("[");Put(L, WIDTH => 3);Put("] ");
      Get(Value);
      Index := L;
      -- Look for a place to put the new value
      while( Index > 1 ) loop
         exit when (Index = 1 or Values(Index-1) < Value);
         Values(Index) := Values(Index-1);
         Index := Index - 1;
      end loop;
      Values(Index) := Value;
   end loop;

   Put_Line("Printing array");
   for M in 1 .. Length loop
      Put("[");Put(M, WIDTH => 3);Put("] ");
      Put(Values(M));
      New_Line;
   end loop;

end Ch2Problem4;
