954,487 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help for Binary Tree Traversal for infix to postfix conversion

Can any one help me in providing help
I am working on Tree Structure

My problem is to take input as an expression like a+b(c/t) and
Using Binary Tree converting it into postfix RPN ab+ct/

muzammilpn
Newbie Poster
2 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

It's pretty simple first create a binary tree, then read the input and insert each element in appropriate place in teh tree, then read it back in postfix notation.
Let us know once you're done with the code if you need more help.

thekashyap
Practically a Posting Shark
811 posts since Feb 2007
Reputation Points: 254
Solved Threads: 75
 

>It's pretty simple first create a binary tree, then read the input and insert
>each element in appropriate place in teh tree, then read it back in postfix notation.
Brilliant. :)

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

It isn't actually that difficult.

Find the operator with the lowest priority, store it as the root node with the left and right expressions as subnodes.
Repeat for both subnodes.

One thing that complicates it a little is characters that can act as both unary and binary operators (-).

Personally, I find using the stack much easier to complete such a task. Look here for ideas.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You