• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1783
  • Last Modified:

Evaluating a Postfix Expression

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
jpipitone
Asked:
jpipitone
  • 2
  • 2
  • 2
  • +3
1 Solution
 
jpipitoneAuthor Commented:
This is actually VERY Urgent.
0
 
ExceterCommented:
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
 
jpipitoneAuthor Commented:
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
Industry Leaders: 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!

 
grg99Commented:
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
 
pankajtiwaryCommented:
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
 
substandCommented:
postfix assumes no order of operations other than the order they are entered.  grg99  is right.
0
 
ExceterCommented:
>> 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
 
Computer101Commented:
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
 
Computer101Commented:
Points refunded and placed in PAQ

Computer101
E-E Admin
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now