Skip to content

Commit 63ed2aa

Browse files
is Node Present Problem Solved - Coding Ninja
1 parent a5736b7 commit 63ed2aa

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Is Node Present.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
template <typename T>
5+
class BinaryTreeNode
6+
{
7+
public:
8+
T data;
9+
BinaryTreeNode<T> *left;
10+
BinaryTreeNode<T> *right;
11+
12+
BinaryTreeNode(T data)
13+
{
14+
this->data = data;
15+
left = NULL;
16+
right = NULL;
17+
}
18+
};
19+
20+
bool isNodePresent(BinaryTreeNode<int> *root, int x)
21+
{
22+
// Write your code here
23+
if (!root)
24+
return;
25+
if (root->data == x)
26+
return true;
27+
bool l = isNodePresent(root->left, x);
28+
bool r = isNodePresent(root->right, x);
29+
return l || r;
30+
}

0 commit comments

Comments
 (0)