Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 11-29-2005, 09:25 AM   #1 (permalink)
tarja
Registered User
 
Join Date: Nov 2005
Posts: 1
tarja is on a distinguished road
postfix help

Hi all, i'm stumped

I'm suppose to write a program that evaluates postfix arithmetic expressions using stacks. any ideas how to turn this into something easy even a simple-mind like myself could understand?

The user types numbers in postfix and it is suppose to output the answer. So, it would look like this : 4 5 2 7 + - * = 16

Any help on this would be greatly appreciated!

Thanks.

~ Tarja
tarja is offline   Reply With Quote
Old 11-29-2005, 01:00 PM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
This is easy but good intro in expression evaluation.

- You have a stack with numbers in it.
- You have some datastructure with the operators in it in the right order of execution.

1) Pop top number of stack and store in a variable.
2) Pop second number of stack and store in another variable.
3) Fetch operator and use it on those two variables.
4) Push result on stack.

Do this until one number and no operators are left. The last number is the answer. If an operator is left with only one number on stack then the expression is invalid.

Good luck!
__________________
Valmont is offline   Reply With Quote
Old 12-01-2005, 06:08 PM   #3 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
So how did it go tarja?
__________________
Valmont is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 03:50 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting