1 #include<bits/stdc++.h> 2 using namespace std; 3 struct node{ 4 node *left,*right; 5 int val; 6 }; 7 void insert(node * &bt,int n) 8 { 9 10 if(bt) 11 { 12 if(bt->val<n)insert(bt->right,n); 13 else if(bt->val>n)insert(bt->left,n); 14 } 15 else 16 { 17 bt=new node; 18 bt->val=n; 19 bt->left=bt->right=nullptr; 20 } 21 } 22 23 node *findnode(node *root,int n) 24 { 25 if(!root)return nullptr; 26 if(root->val>n)return findnode(root->left,n); 27 else if(root->val<n)return findnode(root->right,n); 28 else return root; 29 } 30 31 int main() 32 { 33 node *root=new node; 34 root->val=0; 35 root->left=root->right=nullptr; 36 for(int i=1;i<=15;i++)insert(root,i); 37 cout<<findnode(root,5)->val<<endl; 38 39 return 0; 40 }