with Ada.Text_IO;
with Ada.Text_IO.Unbounded_IO;
with Ada.Strings.Unbounded;      use Ada.Strings.Unbounded;
with Ada.Containers.Vectors;     use Ada.Containers;
 
procedure Quotes is
   package IO renames Ada.Text_IO;
   package SUIO renames Ada.Text_IO.Unbounded_IO;
   package Quote_Container is new Vectors (Natural, Unbounded_String);
   use Quote_Container;
   Quotes    : Vector;
   Input     : IO.File_Type;
   Bubbling  : Boolean := True;
begin
   IO.Open (File => Input,
            Mode => IO.In_File,
            Name => "quotes.txt");
   while not IO.End_Of_File (File => Input) loop
      Quotes.Append (New_Item => SUIO.Get_Line (File => Input));
   end loop;
   IO.Close (Input);
 
   while Bubbling loop
      Bubbling := False;
      for i in Quotes.First_Index .. Quotes.Last_Index loop
         if i /= Quotes.Last_Index then
            if Quotes.Element (i) > Quotes.Element (i + 1) then
               Quotes.Swap (I => i,
                            J => i + 1);
               Bubbling := True;
            end if;
         end if;
      end loop;
   end loop;
 
   for i in Quotes.First_Index .. Quotes.Last_Index loop
      SUIO.Put_Line (Item => Quotes.Element (Index => i));
   end loop;
end Quotes;

Go back


Navigation