From 727e3c59346da4f91284b34b4c18f2e0ba155e53 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 9 Aug 2025 16:03:28 +0200 Subject: Initial commit --- list/list.gpr | 5 +++++ list/src/list.adb | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 list/list.gpr create mode 100644 list/src/list.adb (limited to 'list') diff --git a/list/list.gpr b/list/list.gpr new file mode 100644 index 0000000..5095383 --- /dev/null +++ b/list/list.gpr @@ -0,0 +1,5 @@ +project List is + for Source_Dirs use ("src"); + for Object_Dir use "obj"; + for Main use ("list.adb"); +end List; diff --git a/list/src/list.adb b/list/src/list.adb new file mode 100644 index 0000000..c8910d6 --- /dev/null +++ b/list/src/list.adb @@ -0,0 +1,46 @@ +with Ada.Text_IO; use Ada.Text_IO; + +procedure List is + + type MyList; + + type MyList_Access is access MyList; + + type MyList is record + Value : Integer := 0; + Next : MyList_Access := null; + end record; + + function Length (XS : access constant MyList) return Integer is + L : Integer := 0; + Node : access constant MyList := XS; + begin + while Node /= null loop + L := L + 1; + Node := Node.Next; + end loop; + return L; + end Length; + + procedure Print_List (XS : access constant MyList) is + begin + if XS /= null then + Put (Integer'Image (XS.Value) & " "); + Print_List (XS.Next); + end if; + end Print_List; + + function Build_List return MyList_Access is + XS : MyList_Access := new MyList'(1, new MyList'(2, new MyList'(3, null))); + begin + return XS; + end Build_List; + + XS : MyList_Access := Build_List; + +begin + Put ("List: "); + Print_List (XS); + New_Line; + Put_Line ("The list has length " & Integer'Image (Length (XS))); +end List; -- cgit v1.2.3