with Generic_Sorted_List;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Text_IO; use Ada.Text_IO;
procedure Pakettest is
type Test_Type is
record
Name : String(1 .. 20);
Name_Length : Integer;
Age : Integer;
end record;
function Get_Key(Object : in Test_Type) return Integer is
begin
return Object.Age;
end Get_Key;
function ">"(Left : in Test_Type;
Right : in Test_Type) return Boolean is
begin
return Get_Key(Left) > Get_Key(Right);
end ">";
function "="(Left : in Test_Type;
Right : in Test_Type) return Boolean is
begin
return Get_Key(Left) = Get_Key(Right);
end "=";
procedure Put(Object : in Test_Type) is
begin
Put_Line(Object.Name(1..Object.Name_Length));
Put(Object.Age);
New_Line;
end Put;
package My_Sorted_List is
new Generic_Sorted_List(Data_Type => Test_Type,
Key_Type => Integer,
Get_Key => Get_Key,
Put => Put,
">" => ">",
"=" => ">");
procedure Get(Item : out Test_Type) is
begin
Get_Line(Item.Name,Item.Name_Length);
if Item.Name_Length = 20 then
Skip_Line;
end if;
Get(Item.Age);
Skip_Line;
end Get;
My_List : My_Sorted_List.List_Type;
Temp : Test_Type;
begin
For I in 1..3 loop
Get(Temp);
My_Sorted_List.Insert(Temp,My_List);
end loop;
My_Sorted_List.Remove(20,My_list);
My_Sorted_List.Put(My_List);
Put(My_Sorted_List.Length(My_List));
end Pakettest;