Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with Ada.Unchecked_Deallocation;
- with Ada.Text_IO; use Ada.Text_IO;
- with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
- with Herohandling; use Herohandling;
- with Stringhandling; use Stringhandling;
- with Ada.Float_Text_IO; use Ada.Float_Text_IO;
- package body Sorted_Hero_List is
- ------------------------------------------------------------------
- function Empty(List_Ptr : in List_Type) return Boolean is
- begin
- if list_Ptr = null then
- return True;
- else
- return False;
- end if;
- end Empty;
- procedure Insert_First(List_Ptr : in out List_Type; hero : in Hero_Type) is
- Temp : List_Type;
- begin
- -- if Empty(List_Ptr) then
- -- List_Ptr := new Node_Type;
- -- List_Ptr.hero := hero;
- -- List_Ptr.Next := null;
- -- else
- Temp := new Node_Type;
- Temp.data := hero;
- Temp.Next := List_Ptr;
- List_Ptr := Temp;
- -- end if;
- end Insert_First;
- ------------------------------------------------------------------------
- procedure Insert(List_Ptr : in out List_Type; hero : in Hero_Type; Soktal : in integer) is
- begin
- if Empty(List_Ptr) then
- Insert_First(List_Ptr,Hero);
- elsif Soktal < Get_Age(List_Ptr.data) then
- Insert_First(List_Ptr,hero);
- else
- Insert(List_Ptr.Next,Hero,soktal);
- end if;
- end Insert;
- ---------------------------------------------------------------------------
- procedure Put (List_Ptr : in List_Type) is
- begin
- if not Empty(List_Ptr) then
- Put(List_Ptr.data);
- New_Line;
- Put(List_Ptr.Next);
- else
- New_Line;
- Put_Line("Vi har nu skrivit ut alla hjältar.");
- end if;
- end Put;
- ---------------------------------------------------------------------------
- function Member(List_Ptr : in List_Type; Soktal : in Integer)
- return Boolean is
- begin
- if Empty(List_Ptr) then
- return False;
- else
- if Soktal = Get_Age(List_Ptr.data) then
- return True;
- else
- return Member(List_Ptr.Next,Soktal);
- end if;
- end if;
- end Member;
- --------------------------------------------------------------------------
- function Find (List_Ptr : in List_Type; Soktal : in Integer)
- return Hero_Type is
- begin
- if Member(List_Ptr,Soktal) = False then
- raise Find_Error;
- else
- if Soktal = Get_Age(List_Ptr.data) then
- return List_Ptr.data;
- else
- return Find(List_Ptr.Next,Soktal);
- end if;
- end if;
- end Find;
- ----------------------------------------------------------------------------
- procedure Find (List_Ptr : in List_Type; Soktal : in Integer; Result : out Hero_type) is
- begin
- Result := Find(List_Ptr,Soktal);
- end Find;
- ---------------------------------------------------------------------
- procedure Free is new Ada.Unchecked_Deallocation(Node_Type, List_Type);
- ---------------------------------------------------------------------
- procedure Remove (List_Ptr : in out List_Type; Soktal : in Integer) is
- Temp : List_Type;
- begin
- if not Empty(List_Ptr) then
- if Get_Age(List_Ptr.data) = Soktal then
- Temp := List_Ptr.Next;
- Free(List_Ptr);
- List_Ptr := Temp;
- else
- Remove(List_Ptr.Next, Soktal);
- end if;
- end if;
- end Remove;
- -------------------------------------------------------------------------
- procedure Delete (List_Ptr : in out List_Type) is
- begin
- if not Empty(List_Ptr) then
- Delete(List_Ptr.Next);
- Free(List_Ptr);
- end if;
- end Delete;
- --------------------------------------------------------------------
- function Length(List_Ptr : in List_Type) return Integer is
- begin
- if Empty(List_Ptr) then
- return 0;
- else return 1+Length(List_Ptr.Next);
- end if;
- end Length;
- end Sorted_Hero_List;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement