c - Finding the size of n-ary tree -


in c, tried find size of n-ary tree this. know why wrong. couldn't find out way return size of n-ary tree.

can suggest way return size of tree.

int size(struct node*root) {     int sz=0;     if(root==null)       return 0;     else     {       for(int i=0;i<n;i++) sz=sz+1+size(root->child[i]);     }   return sz; } 

try this:

int size(struct node*root) {     int sz=1;     if(!root) return 0;     for(int i=0;i<n;i++) sz+=size(root->child[i]);     return sz; } 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -