1,105,286 Community Members

How to add data (logical operator) recursively in a binary tree

Member Avatar
jkembo
Newbie Poster
11 posts since Jun 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I am stuck, I know how binary tree works, but I don't have any clue how to add data recursively in a binary tree.

The user needs to enter a formula with logical operators.
If the user presses to a button e.g NOT(unary operator), then it should display at follow : NOT(...)
Then instead of the 3 dots the user can enter manually a letter "b" or another operator by pressing any of the button (e.g AND) which is a binary operator.

NOT ( (...) AND (...)), then again the user have the choice to enter a letter or to press another button on the left hand-side and then on the right hand-side of the AND connector. NOT ( ( b ) AND ( a )).

This formula is terminated has AND is the root. and b and a are leaves.

but i dont know how to code this in java.

NEED HELP please i am struggling for almost 2 weeks

Attachments Screen_shot_2012-01-26_at_03.14_.12_.png 21.6KB
Member Avatar
JamesCherrill
... trying to help
10,362 posts since Apr 2008
Reputation Points: 2,081 [?]
Q&As Helped to Solve: 1,749 [?]
Skill Endorsements: 47 [?]
Moderator
Featured
 
1
 

"NOT ( ( b ) AND ( a )) ... This formula is terminated has AND is the root"

Are you sure? I would expect the resulting tree to look like this:

NOT
                /   \
               /     \
            (null)   AND
                    /   \
                   /     \
                  a       b
Member Avatar
jkembo
Newbie Poster
11 posts since Jun 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

:) You are right and it makes more sense... I think that's why I could not figure out the next steps... But I am still stuck :'(

Do you have any idea?

Member Avatar
jkembo
Newbie Poster
11 posts since Jun 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

You are right and it makes more sense... I think that's why I could not figure out the next steps... But I am still stuck :(

Member Avatar
JamesCherrill
... trying to help
10,362 posts since Apr 2008
Reputation Points: 2,081 [?]
Q&As Helped to Solve: 1,749 [?]
Skill Endorsements: 47 [?]
Moderator
Featured
 
1
 

Something like:
When the user selects the first operator that is the first node. When the use puts something in the ... to its left, that becomes the left sub-node of that node, similarly for the right ...
If one of those sub-nodes is another operator then that's a new node with its own left and right sub-nodes.

Maybe you just need to start coding something - eg just entering (a AND b) (no recursion needed here) then what you learn from doing that will help you towards the next step.

Question Answered as of 2 Years Ago by JamesCherrill
Member Avatar
jkembo
Newbie Poster
11 posts since Jun 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Thank you very much i was going on the wrong track :)... will try

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: