Differences

This shows you the differences between two versions of the page.

Link to this comparison view

vectors.generic_sorting.merge [2012/01/24 08:08] (current)
thomaslocke created
Line 1: Line 1:
 +<code ada>
 +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;
 +   ​Foo_Bar ​  : Vector;
 +   ​Input ​    : IO.File_Type;​
 +   ​package A_Sorter is new Generic_Sorting;​
 +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);
 +
 +   ​Foo_Bar.Append (New_Item => To_Unbounded_String ("​Foo"​));​
 +   ​Foo_Bar.Append (New_Item => To_Unbounded_String ("​Bar"​));​
 +
 +   ​A_Sorter.Sort (Container => Foo_Bar);
 +   ​A_Sorter.Sort (Container => Quotes);
 +
 +   ​A_Sorter.Merge (Target => Foo_Bar,
 +                   ​Source => Quotes);
 +
 +   for i in Foo_Bar.First_Index .. Foo_Bar.Last_Index loop
 +      SUIO.Put_Line (Item => Foo_Bar.Element (Index => i));
 +   end loop;
 +   
 +   ​IO.Put_Line (Item => "​Length of Quotes:"​ & Quotes.Length'​Img);​
 +end Quotes;
 +</​code>​
 +
 +[[Ada.Containers.Vectors#​Generic_Sorting.Merge | Go back]]
  

Navigation