im trying to implement a calculator
but the trouble im having is when i have two negative signs should be positive.
so if i have a tree like
then the final tree should just beCode:- / \ - / \ 1
ive been trying to think of an algorithm or a way to code this but.. no luck..Code:1 / \
im thinking it can be done recursively..
what i have tried to do is..
1. if root node is a '-'
2. if root->rightside is a '-'
3. then create a temp node, which has the root as whatever root->rightside->rightside is. in this case it would be the '1'.
4. return this new node and then return to top of function and it'll fall into one of the normal cases of just a number and it gets taken care of .. no more worries..
but will this work if i have more '-'..
in this case it should returnCode:- / \ - / \ - / \ 1
Code:- / \ 1
.. any help anybody ?