Inserting element into a binary tree-function - Programmers Heaven

Howdy, Stranger!

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

Categories

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.