You are on page 1of 1

#include<iostream> using namespace std; typedef struct nod {nod *st; int info ; nod *dr; }*arb ; arb

rad; void CABC(arb &r,int k) // creare arbore binar de cautare {if(r) {if(r->info!=k) if(r->info>k)CABC(r->st, k); else CABC(r->dr,k); } else {r=new nod; r->info=k; r->st=NULL; r->dr=NULL; } } int cauta(arb r , int k) // verifica daca un nr se gaseste in arb si {if(!r)return 0; if(r->info==k)return 1; if(r->info > k)return cauta(r->st,k); else return cauta (r->dr, k); } int main () {int n,i,x,p; cout<<"p=";cin>>p; cout<<"n=";cin>>n; for(i=1;i<=n;i++) {cout<<"x=";cin>>x; CABC(rad ,x); } if(cauta(rad,p))cout<<"nr "<<p<<" se gaseste in arbore"; else cout<<"nr "<<p<<" nu se gaseste in arbore"; return 0; }