with Ada.Unchecked_Deallocation;
package body Stacks is
   procedure Free is new Ada.Unchecked_Deallocation (Node, Node_Ptr);

   procedure Push (S : in out Stack; X : Integer) is
   begin
      S.Top := new Node'(Value => X, Next => S.Top);
      S.Count := S.Count + 1;
   end Push;

   procedure Pop (S : in out Stack; X : out Integer) is
      First : Node_Ptr := S.Top;
      Again : Node_Ptr := S.Top;
   begin
      X := S.Top.Value;
      S.Top := S.Top.Next;
      S.Count := S.Count - 1;
      Free (First);
      Free (Again);
   end Pop;
end Stacks;
