So I'm trying to implement level order traversal for a binary tree off the top of my head. I feel like I am missing a return statement but is it absolutely necessary to have a return statement in a recursive function?
And is it okay that it took me about an hour to do this? I think I'm still trying to wrap my head around recursion.
So it's okay to do something recursive without having a return statement? I'm just concerned with memory here. So once the function ends the stack is released right?
Memory on the heap is the one I should be concerned about manually freeing?
So it's okay to do something recursive without having a return statement?
It is okay as long as your function is declared as returning nothing (void).
As soon as function ends all automatic variables are destroyed. return statement does not make a difference here. But if your function does return something and you did not place anything on stack (by return statement), then you have problems.