-
Infix to postfix
Hey everyone!
I'm looking for an algoritem which converts an infix squence to postfix. My problem is that I don't know what to do with the brackets in the squence. Here's what I have so far...
counter=0
init(stack)
While not end of line
read x
if x is a number
print x
counter++
else //x is an oprenad
push(stack,x)
if counter==2
y=pop(stack)
print y
counter=0
while not_empty(stack)
y=pop(stack)
print y
I believe this would work if converted into code. How do I make it work if the expression contains brackets? i dont want the output to have any brackets in it
I would appreciate any help you could offer, and no code is needed (just an algoritem).
Thanks
-
argh why can't i post spaces?
Hey everyone!
I'm looking for an algoritem which converts an infix squence to postfix. My problem is that I don't know what to do with the brackets in the squence. Here's what I have so far...
BEGIN
counter=0
init(stack)
While not end of line
{read x
if x is a number
{print x
counter++}
else //x is an oprenad
{push(stack,x)}
if counter==2
{y=pop(stack)
print y
counter=0}
}
while not_empty(stack)
{y=pop(stack)
print y}
END
I hope it's clearer now....
-