We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5d1e291 commit 6cb1162Copy full SHA for 6cb1162
Trees/btreeCountNodes.java
@@ -0,0 +1,45 @@
1
+
2
+class Node
3
+{
4
+ int data;
5
+ Node left;
6
+ Node right;
7
+ Node(int data)
8
+ {
9
+ this.data=data;
10
+ left=right=null;
11
+ }
12
+}
13
14
+class BinaryTree{
15
+ Node root;
16
+ BinaryTree()
17
18
+ root = null;
19
20
+ BinaryTree(int data)
21
22
+ this.root=new Node(data);
23
24
+ int count(Node head)
25
26
27
+ if(head==null)
28
29
+ return 0;
30
31
+ return 1+count(head.left)+count(head.right);
32
33
34
35
+class btreeCountNodes{
36
+ public static void main(String[] args) {
37
38
+ BinaryTree bt=new BinaryTree(2);
39
+ bt.root.left=new Node(3);
40
+ bt.root.right=new Node(5);
41
+ bt.root.left.right=new Node(9);
42
+ bt.root.right.left=new Node(7);
43
+ System.out.println(bt.count(bt.root));
44
45
0 commit comments