943,648 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 2474
  • C RSS
Jul 12th, 2009
0

Postfix operation

Expand Post »
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sumeetdesaeee is offline Offline
11 posts
since Jul 2009
Jul 12th, 2009
0

Re: Postfix operation

> Sample question:- Wat will the expression ABC AB AC will become after postfix operation??
You need to post some actual C code.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Jul 12th, 2009
0

Re: Postfix operation

are you talking about postfix operator as ++a or --a or you referring to postfix expression as in +ab will become a+b??
Reputation Points: 10
Solved Threads: 1
Newbie Poster
praveenraj1987 is offline Offline
4 posts
since Sep 2008
Jul 12th, 2009
0

Re: Postfix operation

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.
Reputation Points: 23
Solved Threads: 6
Light Poster
abhi.navale is offline Offline
38 posts
since Apr 2009
Jul 12th, 2009
0

Re: Postfix operation

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.
Reputation Points: 17
Solved Threads: 16
Junior Poster
s_sridhar is offline Offline
139 posts
since Mar 2009
Jul 12th, 2009
0

Re: Postfix operation

Sample question:- Wat will the expression ABC AB AC will become after postfix operation??
The expression contains only operands. Where are the operators?

If you have a string in infix, ie. in form A+B, and you wish to have it in the form AB+, you can use the Shunting Yard Algorithm
Reputation Points: 32
Solved Threads: 14
Junior Poster
tuse is offline Offline
173 posts
since Jul 2007
Jul 12th, 2009
0

Re: Postfix operation

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..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sumeetdesaeee is offline Offline
11 posts
since Jul 2009
Jul 12th, 2009
1

Re: Postfix operation

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.

Hope this helps
Reputation Points: 32
Solved Threads: 14
Junior Poster
tuse is offline Offline
173 posts
since Jul 2007
Jul 13th, 2009
0

Re: Postfix operation

Ok friends....thanks a lot......I got it......
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sumeetdesaeee is offline Offline
11 posts
since Jul 2009
Jul 14th, 2009
0

Re: Postfix operation

postfix evaluation:
===================

question: AB+C-DE+*
steps:
1)group like this

(AB+) C-DE+*
-----
lets say AB+ (means A+B) is x then

2)(xC-)DE+*
-----
(k)

3)then

k(DE+)*
----
(z)

4)then
kz* means k*z is the answer.

postfix to infix convertion:
===========================
1) AB+C-DE+*

2)((AB+)C-)(DE+)*

put bracket like this where two operand and one operand should be there in this manner.

now change the operand in the last to middle.like

3)((A+B)C-)(DE+)*

4)((A+B)-C)(D+E)*

5)((A+B)-C)*(D+E) it will your final infix expression.

postfix to prefix convertion:
=============================
1) AB+C-DE+*

2)((AB+)C-)(DE+)*

put bracket like this where two operand and one operand should be there in this manner.
now bring the operation from the beginning to the end.

3)((+AB)C-)(DE+)*

4)*(-(+AB)C)(+DE)

5)now remove all the brackets.

6)*-+ABC+DE ====its the answer.

I have given your the fastest tips to solve these kind of problems.

In case of any problem you face let me know.

Thanks,
DP
Last edited by Dream2code; Jul 14th, 2009 at 7:51 am.
Reputation Points: 22
Solved Threads: 12
Junior Poster
Dream2code is offline Offline
144 posts
since Jun 2009

This thread is solved

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.
Message:
Previous Thread in C Forum Timeline: String Swap Not Working
Next Thread in C Forum Timeline: How cn i change a windows folder





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC