I want to understand the following code:
struct element{
element *a1;
element *a2;
int value;
};
void main(){
element e6 = { NULL, NULL, 6 };
element e2 = { NULL, NULL, 2 };
element e4 = { NULL, NULL, 4 };
element e7 = { &e6, NULL, 7 };
element e9 = { NULL, NULL, 9 };
element e3 = { &e2, &e4, 3 };
element e8 = { &e7, &e9, 8 };
element e5 = { &e3, &e8, 5 };
cout << CountList(&e5) << endl;
return;}
int CountList(element *e){
int c=1;
if(e){
c=c+CountList(e->a1);
c=c+CountList(e->a2);
return c;}
return 0;
}
the count is 8. But how can I understand the recursion line ?? my Idea was, that the Count must be 6, because the recursion function are called only 4 times. The Compiler says 8, which is already the correct solution. But why??
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)