Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
42
Task/Stack/Ada/stack-2.ada
Normal file
42
Task/Stack/Ada/stack-2.ada
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
with Ada.Unchecked_Deallocation;
|
||||
|
||||
package body Generic_Stack is
|
||||
|
||||
------------
|
||||
-- Create --
|
||||
------------
|
||||
|
||||
function Create return Stack is
|
||||
begin
|
||||
return (null);
|
||||
end Create;
|
||||
|
||||
----------
|
||||
-- Push --
|
||||
----------
|
||||
|
||||
procedure Push(Item : Element_Type; Onto : in out Stack) is
|
||||
Temp : Stack := new Node;
|
||||
begin
|
||||
Temp.Element := Item;
|
||||
Temp.Next := Onto;
|
||||
Onto := Temp;
|
||||
end Push;
|
||||
|
||||
---------
|
||||
-- Pop --
|
||||
---------
|
||||
|
||||
procedure Pop(Item : out Element_Type; From : in out Stack) is
|
||||
procedure Free is new Ada.Unchecked_Deallocation(Node, Stack);
|
||||
Temp : Stack := From;
|
||||
begin
|
||||
if Temp = null then
|
||||
raise Stack_Empty_Error;
|
||||
end if;
|
||||
Item := Temp.Element;
|
||||
From := Temp.Next;
|
||||
Free(Temp);
|
||||
end Pop;
|
||||
|
||||
end Generic_Stack;
|
||||
Loading…
Add table
Add a link
Reference in a new issue