# Algorithms: Binary tree

Simple implementation of binary tree in C++

```#include<iostream.h>
/**************************************
Tree Node structure - contains data, left and right children
**************************************/
template <class T>
struct TreeNode {
T data;
TreeNode *left;
TreeNode *right;

TreeNode() {
left = NULL;
right = NULL;
this->data = T();
}

TreeNode(T data) {
left = NULL;
right = NULL;
this->data = data;
}
};
/**************************************
Binary Tree class implementation
**************************************/
template <class T> class BinTree {
TreeNode<T> *root;
private:
if (data > node->data) {
if(node->right == NULL) {
TreeNode<T> *n = new TreeNode<T>(data);
node->right = n;
} else {
// go to right branch
}
} else if (data < node->data) {
if(node->left == NULL) {
TreeNode<T> *n = new TreeNode<T>(data);
node->left = n;
} else {
// go to left branch
}
} else {
// do nothing - we already have this node in tree
}
}

bool Find(TreeNode<T> *node, T data){
T nodeData = node->data;
cout << " " << nodeData;

if(nodeData == data) {
return true;
} else if(data > nodeData) {
if(node->right == NULL) {
return false;
} else {
return Find(node->right, data);
}
} else {
if(node->left == NULL) {
return false;
} else {
return Find(node->left, data);
}
}
}
public:
BinTree(){
root = NULL;
}

if(root == NULL) {
TreeNode<int> *n = new TreeNode<int>(data);
root = n;
} else {
}
}

bool Find(T data) {
if(root->data == data){
cout << " " << data;
return true;
} else {
return Find(root, data);
}
}
};

int main (int argc, char *argv[]) {
BinTree<int> *tree = new BinTree<int>();

`Searching for 7: 12 5 8 7 - FOUND`