Skip to content

Commit 75af12a

Browse files
authored
--added countNodes() - count no of nodes in a tree
1 parent 574f2b4 commit 75af12a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Chapter-8/BinaryTreeImplementation.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,12 @@ public void delete(int key) {
167167

168168
}
169169

170-
170+
public int countNodes(Node root) {
171+
if(root == null)
172+
return 0;
173+
174+
return countNodes(root.left) + 1 + countNodes(root.right);
175+
}
171176

172177
public void inOrderPrint(Node root){
173178
if(root == null)

0 commit comments

Comments
 (0)