public int mystery(int b)
{
if (b == 0)
return 0;
if (b % 2 == 0)
return mystery(b - 1) + 3; // call 1
else
return mystery(b - 1) + 2; // call 2
}
Call stack
m(5)
Explanation
Since mystery
has more than one call to itself, the calls are labeled. It doesn’t matter which call is labeled call 1
and which is labeled call 2
, as long as the usage is consistent.
The initial call to mystery(5)
is added to the stack, abbreviated as m(5)
.