The I/p to the algo will be an expression like this:
a+(-b)
a*-b+c
i.e any expression that a standard C compiler would support.
Now
You could simply convert -6
to 06-
to eliminate unary operators completely. I like this approach since it is more orthogonal and you do not need to take care of special cases when processing.
An alternative approach is to use different symbols for the unary and the binary versions of operators using the same symbol, eg. -
remains binary minus and ~
becomes negation sign.