Saved Bookmarks
| 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 (T→left == NULL && T→right = NULL) n++ leafcount (T→right) } return (n);} (ii) Leafcount (T) { static int n=0; if (T! = NULL) {leaf count (T→ left); if (T→left!= NULL && T→right! = NULL) n++ leafcount (T→right) } return (n);} |
|