?
Solved

Evaluating a Postfix Expression

Posted on 2003-03-26
9
Medium Priority
?
1,780 Views
Last Modified: 2008-03-06
I am looking for code to compile in Visual C++ 6.0 or .NET that simply evaluates a Postfix expression using stacks (pop, push, etc).  I was working on a different program that converted infix to postfix expressions, but it's not what I needed.  Can anyone help?

Thanks
0
Comment
Question by:jpipitone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 1

Author Comment

by:jpipitone
ID: 8212593
This is actually VERY Urgent.
0
 
LVL 8

Expert Comment

by:Exceter
ID: 8212626
Check this out,
http://programmersheaven.com/zone3/cat478/24213.htm

Note: This code has some Borland specific functions in it. It shouldn't be very hard to remove them, however, becuase they are used int the user interface and not the actual algorithm.

Exceter
0
 
LVL 1

Author Comment

by:jpipitone
ID: 8212992
This definitely helps, but I cannot have that function in there to convert, and the borland stuff I can't have either.  Basically I have no time on my hands to do this right now and it's needed ASAP!!

Thank you though, I can accept that for an answer, can you give me suggestions on how to get rid of unneeded code?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 22

Expert Comment

by:grg99
ID: 8213554
A postfix evaluator is REALLY easy:

See a string of digits?  evaluate them, push on stack.

See an operator?  Do it to the top two stack elements.

Can be done in under a page of code, no sweat.

Just attack it one step at a time, you'll eventually get it.

0
 
LVL 4

Expert Comment

by:pankajtiwary
ID: 8216061
Look friend,
    When you are evaluating a postfix expression we assume that the operands are of sigle digit. Here you have to create two stacks. One for the operators and the other for the operands. Now read the input string one charecter at a time. If its a number push it into the operands stack and if its an operator(+, -, *, /) push it into the operators stack. Now at any point of time you see that a high priority operator sits on top of a low priority operator, pop the top 2 operands from the oprands stack and pop one item from the operators stack, evaluate them and push the result into the operands stack. Do this till you are at the end of the input string.
    When the string finishes, keep on pop 2 items from the operands stack and 1 from the operators stack, evaluate it and push the result into operands stack until both the stacks become empty. This will solve your problem if you code correctly. This is the basic operation for evaluating postfix expressions I have ever seen.
0
 
LVL 10

Expert Comment

by:substand
ID: 8217043
postfix assumes no order of operations other than the order they are entered.  grg99  is right.
0
 
LVL 8

Expert Comment

by:Exceter
ID: 8219383
>> Can be done in under a page of code, no sweat.

Quite true.

>> When you are evaluating a postfix expression we assume that the operands are of sigle digit.

Maybe you do, I don't. :-)

>> postfix assumes no order of operations other than the order they are entered.

Correct.

Exceter
0
 
LVL 1

Expert Comment

by:Computer101
ID: 8236011
A request for deletion has been made.  If no response or you feel this is in error, comment.  If no objection, I will delete in three days.

Computer101
E-E Admin
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 8275487
Points refunded and placed in PAQ

Computer101
E-E Admin
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Suggested Courses
Course of the Month10 days, 1 hour left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question