I recently appeared for the entrance of cdac.
There I found a lot of questions about postfix.(I know the postfix operator commonly used in c.But it wasn't that way.)
Sample question:- Wat will the expression ABC AB AC will become after postfix operation??
Please tell me how to deal with such questions???
And since I am a new user,if I have made any mistake in method of creating a new thread,pls forgive me for that.
it is not postfix / prefix in 'c' language i.e. it is not ++a (pre increment 'a') or b-- (post decrement 'b')
it a postfix/prefix which referes to conversion of human readable mathematical expression into computer readable mathematical expression.
when we see "solve a+b" then we just do a plus b
but computer dont understand what 'a+b' means
to let computer understand what 'a+b' means we convert it to postfix expresstion
prefix meas we arrange our expression in such a way that all operators(+,/,-,*) will come first and then oprands (i.e. a,b, etc.)
in same way postfix means operatos will be at end and operands will come first
example : solve a+b , then
conversion of above example in prefix: +ab
conversion of above example in postfix: ab+
there are some algo to do this conversion. also there are many application of postfix/prefix string expressiotn like stack, string reverse etc.
Last edited by abhi.navale; Jul 12th, 2009 at 6:18 am.
Postfix expression is used to aid the order of evaluation of a mathematical expression.
When higher level programming languages came into existence one of the major hurdles faced by computer scientists was to generate machine language instructions that would properly evaluate any arithmetic expression.
for eg. A*B/C is AB*C/ in postfix notation.
Notice three features of postfix expression:
-The operands maintain the same order as in the equivalent infix expression.
-Parantheses are notneeded to designate the expression unambiguously
-While evaluating the postfix expression the priority of the operators is no longer relevant.
I am talking about postfix expression as in +ab will become a+b.
Can u pls explain it properly ???
And pls also tell me in which book i will get it so that I can have some more reference..
That is just the reverse of the aforementioned algorithm.
Explanation- Scan the input string from left to right. Whenever you see an operand, just push it onto a stack. When you encounter an operator, pop two elements and concatenate the operator between the two operands and push it back to the stack. Perform this till the input string is fully parsed. The only element left in the stack (if the postfix expression is valid) will be the required infix expression.
eg- AB+
1. push A to stack
2. push B to stack
3. Next element is '+'. pop two elements, B and A apply the operator (A+B) and push it back to stack
4. Since you have fully examined the input string, the element left in the stack is the required expression.
This is just a very basic explanation, google for a more precise technique
ps- the thread name says 'postfix' but in your post, you have given a prefix string (+AB). In such a case just parse the input dtring from R->L in the algorithm.
Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
This thread is more than three months old
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.