here's the infix expression:

EXAMPLE 1 a/(b+c)*d

according to me, if * is given higher precedence then / , then this should be the postfix expression:

1) abc+d*/

if / has higher priority then * , then:

2) abc+/d*

question 1: which is correct?? 1 or 2 ?


according to this link, http://www.cs.man.ac.uk/~pjj/cs212/fix.html

EXAMPLE 2 a*(b+c)/d gives abc+*d/ , in which case i think its assumed :

1)either * and / are given same priority, and the algo when checking priority, pops out the operator on stack if the priority of operator on stack[top] >= operator scanned from infix
i emphasize >=

and if that's true, ie, priority of *,/ are same, then EXAMPLE 1 should yield to abc+/d*
question 2: am i correct?

2) * is given higher precedence, and hence it was popped out when / was encountered.

i'm confused about this. nowhere is there any proper documentation about precedence, and how to evaluate if even say, *,/ are given same priorities, occur one after the another, just like in EXAMPLE 2


please reply fast. i want to code accordingly

pls answer accordingly, like question 1 then 2

does that mean in an expression if * comes before / or vice versa, the first one will be popped out?

priority 5 and left-to-right associativity should mean / is executed before.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.