Saved Bookmarks
| 1. |
Write Java code to count number of nodes in a binary tree |
|
Answer» int countNodes(Node root) { int count = 1; //Root itself should be counted if (root ==null) return 0; else { count += countNodes(root.left); count += countNodes(root.right); return count; } } |
|