summaryrefslogtreecommitdiff
path: root/stack/src/stack.adb
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2025-08-09 16:03:28 +0200
committer3gg <3gg@shellblade.net>2025-08-09 16:03:28 +0200
commit727e3c59346da4f91284b34b4c18f2e0ba155e53 (patch)
tree807dccd5cba3c6bae2f8d0c9910157e306c6da5b /stack/src/stack.adb
Initial commitHEADmain
Diffstat (limited to 'stack/src/stack.adb')
-rw-r--r--stack/src/stack.adb31
1 files changed, 31 insertions, 0 deletions
diff --git a/stack/src/stack.adb b/stack/src/stack.adb
new file mode 100644
index 0000000..4dc8fb1
--- /dev/null
+++ b/stack/src/stack.adb
@@ -0,0 +1,31 @@
1with Ada.Unchecked_Deallocation;
2
3package body Stack is
4 procedure Free is new Ada.Unchecked_Deallocation (Node, Node_Access);
5
6 procedure Push (S : in out Stack; Val : T) is
7 New_Top : Node_Access := new Node;
8 begin
9 New_Top.Val := Val;
10 New_Top.Bottom := S.Top;
11 S.Top := New_Top;
12 end Push;
13
14 function Pop (S : in out Stack; Val : out T) return Boolean is
15 Old_Top : Node_Access := S.Top;
16 begin
17 if Old_Top /= null then
18 Val := Old_Top.Val;
19 S.Top := Old_Top.Bottom;
20 Free (Old_Top);
21 return True;
22 else
23 return False;
24 end if;
25 end Pop;
26
27 function Empty (S : Stack) return Boolean is
28 begin
29 return S.Top = null;
30 end Empty;
31end Stack;