one test is not passing this is my code
#include
using namespace std;
class node{
public:
int data;
node* lt;
node* rt;
node(int d){
data=d;
lt=NULL;
rt=NULL;
}
};
void buildbt(node* rot){
if(rot==NULL){return;}
string ls;
cin>>ls;
if(ls==“true”){
int dd;
cin>>dd;
node* tem=new node(dd);
rot->lt=tem;
buildbt(rot->lt);
}
string rs;
cin>>rs;
if(rs==“true”){
int dd;
cin>>dd;
node* tem=new node(dd);
rot->rt=tem;
buildbt(rot->rt);
}
}
void remlef(node* rot){
if(rot==NULL){return;}
if(rot->lt!=NULL){
if(rot->lt->lt==NULL&&rot->lt->rt==NULL){
rot->lt=NULL;
}}
if(rot->rt!=NULL){
if(rot->rt->lt==NULL&&rot->rt->rt==NULL){
rot->rt=NULL;
}}
remlef(rot->lt);
remlef(rot->rt);
}
void prnt(node* rot){
if(rot==NULL){
return;
}
if(rot->lt!=NULL&&rot->rt!=NULL){
cout<lt->data<<" => “<data<<” <= “<rt->data<<endl;}
else if(rot->lt==NULL&&rot->rt!=NULL){
cout<<“END =>”<data<<” <= “<rt->data<<endl;
}
else if(rot->lt!=NULL&&rot->rt==NULL){
cout<lt->data<<” => “<data<<” <= END"<<endl;
}
else{
cout<<“END => “<data<<” <= END”<<endl;
}
prnt(rot->lt);
prnt(rot->rt);
}
int main(){
int d;
cin>>d;
node* rot=new node(d);
buildbt(rot);
remlef(rot);
prnt(rot);
return 0;
}
What is wrong with my code?
your code look correct
i think there is something missing in prnt function
Code
plz check this code now
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.