with ada.text_io; use ada.text_io; 
with ada.integer_text_io; use ada.integer_text_io; 

with ada.strings.unbounded; 

package body intstackpkg.utils is

    procedure put(s: stacktype) is
    begin
        for i in reverse 1 .. s.TheTop loop
            put(s.elements(i));
            new_line;
        end loop;
    end put;

    ------------------------------------------------------
    function toString(s: stacktype) return string is
        use ada.strings.unbounded;
        ans: unbounded_string := to_unbounded_string("");
    begin
        for i in reverse 1 .. s.TheTop loop
            ans := ans & to_unbounded_string(s.elements(i)'img);
        end loop;
        return to_string(ans);
    end toString;

    ------------------------------------------------------
    function size(s: Stacktype) return Integer is
    begin
        return s.TheTop;
    end size;

    ------------------------------------------------------
    procedure clear(s: in out Stacktype) is
        -- temp: Stacktype;
    begin
        -- s := temp;
        s.TheTop := 0;
    end clear;

    ------------------------------------------------------
    procedure reverseIt(s: in out Stacktype) is
        temp: Stacktype;
    begin
        temp.TheTop := s.TheTop;
        -- for i in 1 .. s.elements'last loop
        for i in 1 .. s.TheTop loop
            temp.elements(i) := s.elements(s.thetop + 1 - I);
        end loop;
        s := temp;
    end reverseIt;

    ------------------------------------------------------
    function reverseIt(s: in Stacktype) return Stacktype is
        temp: Stacktype;
    begin
        temp.TheTop := s.TheTop;
        for i in 1 .. s.TheTop loop
            temp.elements(i) := s.elements(s.thetop + 1 - I);
        end loop;
        return temp;
    end reverseIt;

end intstackpkg.utils;