Reversable Stack Child Body
MC logo

Reversable Stack Child Body

Ada Code Examples

<<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.
      -- Empty is easy.
      if S = null then
      end if;

      -- Init the pointers.
      Back := null;
      Fwd := Node_Ptr(S);

      -- Do the reverse.
         -- 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>>