There is a recursive function f()
. It is looking at cond
and then either returning or executing f()
then g()
. Consider cond
to be an external variable that can be set somewhere else, perhaps in a different thread.
If the first five times
cond
is checked,cond == true
, but the sixth time,cond == false
, describe the code flow.Because this is recursive, the code could suffer from a stack overflow if
cond == true
for too long. Fill in the functioniterative_f()
so that the code flow is identical to the code flow in (1).//recursive void f() { if(cond == false) return; f(); g(); } //iterative void iterative_f() { }