I'm trying to understand why am I getting the result that I am. Lets say that this is the code and result:
Sorry if this is trivial, but there isn't too many sources online about this... If the output of d(3) makes sense to me, then e(3) doesn't at all.
why does moving the write in cases like this reverse the order?
I'm guessing it has something to do with the recursion, but I'm still clueless at why.
This is because in the first case: You first write and then recursively call d(N1)
, so for example d(3)
will write 3
and then call d(2)
etc...
In the second case: You first call e(N1)
and then write and this changes the order because for example e(1)
will call e(0)
which will call e(-1)
which will succeed and then e(0)
will write 0
then e(1)
will write 1
and so on...