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;
- package body Sorted_list is
- function Empty(List_Ptr : in List_Type) return Boolean is
- begin
- return List_Ptr = null;
- end Empty;
- ----------------------------------------------------------------------------------
- procedure Insert_First(List_Ptr : in out List_Type; tal : in Integer) is
- Temp : List_Type;
- begin
- if Empty(List_Ptr) then
- List_ptr := new Node_Type;
- List_ptr.Heltal := Tal;
- List_ptr.Next:= null;
- else
- Temp := new Node_Type;
- Temp.heltal := Tal;
- Temp.Next:= List_ptr;
- List_ptr := Temp;
- end if;
- end Insert_First;
- ----------------------------------------------------------------------------------------------------
- procedure Insert(List_Ptr : in out List_Type; Tal : in Integer) is
- begin
- if Empty(List_Ptr) then
- Insert_First(List_Ptr,Tal);
- elsif Tal < List_Ptr.Heltal then
- Insert_First(List_Ptr,Tal);
- else
- Insert(List_Ptr.Next,Tal);
- end if;
- end Insert;
- List_ptr : List_Type;
- procedure Put(List_Ptr : in List_Type) is
- begin
- if not Empty(List_Ptr) then
- Put(List_Ptr.Heltal, Width=>0);
- New_Line;
- Put(List_Ptr.Next);
- 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;
- elsif Soktal = List_Ptr.Heltal then
- return True;
- else
- return Member(List_ptr.Next,Soktal);
- end if;
- end Member;
- function Find (List_Ptr : in List_Type; Soktal : in Integer)
- return Integer is
- begin
- if Empty(List_Ptr)then
- raise Find_Error;
- else
- if Soktal = List_Ptr.Heltal then
- return List_Ptr.Heltal;
- 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 Integer) 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
- procedure Remove_Process(List_Ptr : in out List_Type; Soktal : in Integer) is
- Temp : List_Type;
- begin
- if not Empty(List_Ptr) then
- if List_Ptr.Heltal = Soktal then
- Temp := List_Ptr.Next;
- Free(List_Ptr);
- List_Ptr := Temp;
- else
- Remove_Process(List_Ptr.Next,Soktal);
- end if;
- end if;
- end Remove_Process;
- begin
- if not Empty(List_Ptr) then
- Remove_Process(List_Ptr,Soktal);
- else
- raise Find_Error;
- end if;
- end Remove;
- procedure Delete(List_Ptr : in out List_Type) is
- begin
- if not Empty(List_Ptr) then
- if List_Ptr.Next = null then
- Free(List_Ptr);
- else
- Delete(List_Ptr.next);
- end if;
- Delete(List_Ptr);
- end if;
- end Delete;
- function Length(List_Ptr : in List_Type; counter : in integer)
- return Integer is
- begin
- if Empty(List_Ptr) then
- return Counter;
- else return Length(List_Ptr.Next, Counter+1);
- end if;
- end Length;
- end Sorted_list;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement