i have an string : (3+5) * (20/4)
i have to convert this string to 3 5 + 20 4 / * (to postfix form)
i cant do this can you tell me how can i do this
i have an string : (3+5) * (20/4)
i have to convert this string to 3 5 + 20 4 / * (to postfix form)
i cant do this can you tell me how can i do this
Put the infix expression into a binary tree where the node is the operator and the left and right subtrees are what is being operated on.
To convert this to postfix, use recursion
postfix(tree T){
if(leftsubtree == null && rightsubtree == null){
print node;
return;
}
if(leftsubtree != null) postfix(leftsubtree);
i(rightsubtree != null) postfix(rightsubtree);
print node;
}
There are a few references on the internet that do this. I wrote my own infix to postfix (in C not C++) and it used a stack which had values and operators pushed and popped off the stack is needed. The code may be a bit hard to read (I often don't comment my little ventures) but if you want it as a reference send me a PM.