1

I need help with adding data to a tree. For example if i have 7+8*9-18/(1+2), how am I supposed to add it to a binary tree in a way that i can compute the result using a binary tree. I am beginner in learning tree structures so I am not very familiar with it.

1
  • 1
    I don't see why u added homework tag. I just made an example. If i want to learn something new it doesn't mean that it is my homework. I didn't ask for you to do this, I just wanted an explanation or a waypoint. Commented Mar 26, 2012 at 18:20

2 Answers 2

1

After converting the post fix expression to infix, follow the below steps to construct a tree.

  1. If it is number, add it to add to the stack.

  2. If is is an operator, make the operator as parent node, pop the element and make it as right child to the parent node, pop the element and make it as left child to the parent node and add the parent node to the stack.

Sign up to request clarification or add additional context in comments.

Comments

0

See How to write an evaluator for a string like "(1+3 * ( 5 / 4)) and get a numeric result and the Shunting Yard Algorithm

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.