Skip to content

Commit 5fcf568

Browse files
authored
Create 14. Count nodes.cpp
1 parent 4ef8fc5 commit 5fcf568

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

008 - Trees/14. Count nodes.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/************************************************************
2+
3+
Following is the structure for the TreeNode class
4+
5+
template <typename T>
6+
class TreeNode {
7+
public:
8+
T data;
9+
vector<TreeNode<T>*> children;
10+
11+
TreeNode(T data) {
12+
this->data = data;
13+
}
14+
15+
~TreeNode() {
16+
for (int i = 0; i < children.size(); i++) {
17+
delete children[i];
18+
}
19+
}
20+
};
21+
22+
************************************************************/
23+
24+
int getLargeNodeCount(TreeNode<int>* root, int x) {
25+
// Write your code here
26+
int count = 0;
27+
for(int i=0;i<root->children.size();i++){
28+
int temp = getLargeNodeCount(root->children[i],x);
29+
count = count+temp;
30+
}
31+
if(root->data > x){
32+
count++;
33+
}
34+
return count;
35+
}

0 commit comments

Comments
 (0)