1.

Write modules to do the following operations on a Binary Tree. (i) Count the number of leaf nodes. (ii) Count the number of nodes with two children.

Answer»

(i ) Leafcount (T)

{

static int n=0; 

if (T!= NULL)

{leaf count (T left); 

if (Tleft == NULL && Tright = NULL) 

n++

leafcount (Tright)

}

return (n);}

(ii) Leafcount (T)

{

static int n=0;

if (T! = NULL)

{leaf count (T left);

if (Tleft!= NULL && Tright! = NULL) 

n++

leafcount (Tright)

}

return (n);} 



Discussion

No Comment Found

Related InterviewSolutions