code.cracker1991
BAN USERHow about this one? Since once mention the Btree I always think of recursive
struct node{
int data;
node *leftch;
node *rightch;
};
void intoatree(struct node **root, int n){
node *temp=new node;
(*temp).data=n;
(*temp).leftch=NULL;
(*temp).rightch=NULL;
node **par;
par=root;
if(*root==NULL){
*root=temp; //insert as the first node
}
else if((*(*par)).data==n){
cout<<"duplicate input"<<endl;
return;
}
else if((*(*par)).data>n){
*par=(*(*par)).leftch;
intoatree(par,n);
}
else{
*par=(*(*par)).rightch;
intoatree(par,n);
}
}
bool prime(int n){
int x;
int upper=n/2+1;
int count=0;
for(x=2;x<=upper;x++){
if((n%x)==0){
count=1;
}
}
if(count){
return false;
}
else {
return true;
}
}
I think for this question it requires to "create" a mirror image , so may we should create them a new tree
- code.cracker1991 December 05, 2013