Iterative implementation of the Ackermann function Here's an iterative implementation of the Ackermann function for review:

#include &lt;stack&gt;
#include &lt;iostream&gt;
#include &lt;tuple&gt;
#include &lt;vector&gt;

int Ackermann(int m, int n) {
    std::stack&lt;int&gt; s;
    s.push(m);
    while (!s.empty()) {
        m = s.top();
        s.pop();
        if (m == 0 || n == 0)
            n += m + 1;
        else {
            s.push(m - 1);
            s.push(m);
            n--;
        }
    }
    return n;
}

int main() {
    std::vector&lt;std::tuple&lt;int, int, int&gt;&gt; tests{
        { 0, 0, 1},
        { 1, 0, 2},
        { 1, 1, 3},
        { 2, 1, 5}
    };

    for (auto const &amp;test : tests) {
        using std::get;

        auto result = Ackermann(get&lt;0&gt;(test), get&lt;1&gt;(test));
        if (result == get&lt;2&gt;(test)) {
            std::cout &lt;&lt; "Ackermann(" 
                       &lt;&lt; get&lt;0&gt;(test) &lt;&lt; ", " 
                       &lt;&lt; get&lt;1&gt;(test) &lt;&lt; ") == " 
                       &lt;&lt; result &lt;&lt; ": passed\n";
        }
        else {
            std::cerr &lt;&lt; "Error: Ackermann(" 
                      &lt;&lt; get&lt;0&gt;(test) &lt;&lt; ", " 
                      &lt;&lt; get&lt;1&gt;(test) 
                      &lt;&lt; ": expected" &lt;&lt; get&lt;2&gt;(test) 
                      &lt;&lt; ", but got: " &lt;&lt; result &lt;&lt; "\n";
        }
    }
}


Any comments appreciated.
The results of the Ackermann function can grow quite large. An int is only guaranteed to cover up to 32767.

A two-dimensional memorization table would probably be worthwhile.