Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Inserting element into a binary tree-function

angssieangssie Posts: 2Member
Hello, i have a problem with inserting an expression on the tree. I have to do a program that puts logical expressions for example: AND AND OR T F T F. I have no idea how to solve it. My current code performs the functions of calculating the value of trees and printing the expression in the tree. Below is my current code of function insertnode, but it is not working properly. Please help me with the problem. Thanks in advance.


[CODE]void insertnode(tree *&root, char newitem, bool operator)
//the parametr operator valuse:1-operator, 0-operand
{
if(root==NULL)
{
root=new tree(newitem);
root->typ=operator;
return;
}
if(root->left!=NULL)
{
if(root->left->typ)
insertnode(root->left,newitem,operator);
}
if(root->right!=NULL)
{
if(root->right->typ)
insertnode(root->right,newitem,operator);
}
if(root->left==NULL)
insertnode(root->left,newitem,operator);
else if(root->right==NULL)
insertnode(root->right,newitem,operator);

}[/CODE]
Sign In or Register to comment.