Reversable Stack Child Body
Reversable Stack Child Package |
Download |
Reversable Stack Client |
package body L_Stack.Reversable is
procedure Rev_Stack(S: in out Int_Stack) is
Fwd, Back: Node_Ptr; -- Forward and backward pointers for rev loop.
Next_Fwd: Node_Ptr; -- Temp for moving forward.
begin
-- Empty is easy.
if S = null then
return;
end if;
-- Init the pointers.
Back := null;
Fwd := Node_Ptr(S);
-- Do the reverse.
loop
-- Get the node that will be next.
Next_Fwd := Fwd.Next;
-- Reverse the pointer.
Fwd.Next := Back;
-- Move up
Back := Fwd;
Fwd := Next_Fwd;
-- Done?
exit when Fwd = null;
end loop;
S := Int_Stack(Back);
end Rev_Stack;
end L_Stack.Reversable;
Reversable Stack Child Package |
Reversable Stack Client |