hi guys could anyone help me with binary tree tying to write functions to check if a binary tree is complete or full or none this is all i did help please
#include <iostream>
using namespace std;
struct bTree
{
int info;
bTree *left;
bTree *right;
};
bTree *root=NULL, *leaf;
void insert(int num, bTree *root);
void postprint(bTree *root);
void preprint(bTree *root);
void reorderprint(bTree *root);
void delbtreeelem(int num);
bool iscomp(bTree* root);
int main()
{
int num;
cin>>num;
while(num!=-1)
{
if(root==NULL)
{
root=new bTree;
root->left=NULL;
root->right=NULL;
root->info=num;
}
else
insert(num, root);
cin>>num;
}
cout<<"left-right-root"<<endl;
postprint(root);
cout<<"\nroot-left-right"<<endl;
preprint(root);
cout<<"\nleft-root-right"<<endl;
reorderprint(root);
cout<<endl;
cout<<"is complete: ";
iscomp(root);
cout<<endl;
cout<<"enter keyto delete"<<endl;
int key;
cin>>key;
delbtreeelem(key);
reorderprint(root);
return 0;
}
void insert(int num, bTree *root)
{
if(num<root->info)
{
if(root->left !=NULL)
insert(num, root->left);
else
{
root->left=new bTree;
root->left->info=num;
root->left->left=NULL;
root->left->right=NULL;
}
}
else if(num > root->info)
{
if(root->right!=NULL)
insert(num, root->right);
else
{
root->right=new bTree;
root->right->info=num;
root->right->left=NULL;
root->right->right=NULL;
}
}
else if(num == root->info)
cout<<"number exists"<<endl;
}
void postprint(bTree *root)
{
if(root !=NULL)
{
postprint(root->left);
postprint(root->right);
cout<<root->info<<" ";
}
}
void preprint(bTree *root)
{
if(root != NULL)
{
cout<<root->info<<" ";
preprint(root->left);
preprint(root->right);
}
}
void reorderprint(bTree *root)
{
if(root != NULL)
{
reorderprint(root->left);
cout<<root->info<<" ";
reorderprint(root->right);
}
}
void delbtreeelem(int key)
{
bTree *temp=root, *parent = root, *marker;
if(temp==NULL)
cout<<"the tree is empty\n";
else
{
while(temp!=NULL && temp->info !=key)
{
parent = temp;
if(temp->info<key)
{
temp=temp->right;
}
else
{
temp=temp->left;
}
}
}
marker =temp;
if(temp==NULL)
cout<<"no node is present\n";
else if(temp==root)
{
if(temp->right==NULL && temp->left==NULL)
{
root=NULL;
}
else if(temp->left == NULL)
{
root=temp->right;
}
else if(temp->right == NULL)
{
root=temp->left;
}
else
{
bTree *temp1;
temp1 = temp->right;
while(temp1->left != NULL)
{
temp=temp1;
temp1=temp1->left;
}
if(temp1 != temp->right)
{
temp->left=temp1->right;
temp1->right=root->right;
}
temp1->left=root->left;
root=temp1;
}
}
else
{
if(temp->right==NULL && temp->left==NULL)
{
if(parent->right==temp)
parent->right=NULL;
else
parent->left=NULL;
}
else if(temp->left==NULL)
{
if(parent->right==temp)
parent->right=temp->right;
else
parent->left=temp->right;
}
else if(temp->right==NULL)
{
if(parent->right==temp)
parent->right=temp->left;
else
parent->left=temp->left;
}
else
{
bTree *temp1;
parent=temp;
temp1=temp->right;
while(temp1->left!=NULL)
{
parent=temp1;
temp1=temp1->left;
}
if(temp1 != temp->right)
{
temp->left=temp1->right;
temp1->right=parent->right;
}
temp1->left=parent->left;
parent=temp1;
}
}
delete marker;
}
bool iscomp(bTree* root)
{
if(root==NULL)
{
cout<<"wrong"<<endl;
}
else
if(root->right && !root->left)
{
cout<<"wrong"<<endl;
return false;
}
else
if( root->left==NULL && root->right==NULL)
{
cout<<"true"<<endl;
return true;
}
else
if((root->left && root->right && iscomp(root->left)
&& iscomp(root->right))||(root->left &&root->right==NULL && iscomp(root->left)))
{
cout<<"true"<<endl;
return true;
}else
return false;
}