Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Stacks (evaluating postfix expression)

1. ## Stacks (evaluating postfix expression)

I'm a little confused so if someone can confirm if I am doing that would be great.

Evaluate postfix expression:

1 2 + 4 * 5 6 * 10 / 8 * +

Me evaluating:

1) 1
2) 2 1
3) 3
4) 4 3
5) 12
6) 5 12
7) 6 5 12
8) 30 12
9) 10 30 12
10) Here's where I get confused. Do I do 30/10 or 10/30 (and is it the same way for subtraction)...3 12
11) 8 3 12
12) 24 12
13) 36

2. ## Re: Stacks (evaluating postfix expression)

From Wikipedia:

Operations which are non-commutative are still written in "conventional order", i.e.:

a b op = a op b

4 2 / = 4 / 2 = 2
2 4 / = 2 / 4 = 0.5

3. ## The Following User Says Thank You to helloworld922 For This Useful Post:

dx8292 (October 6th, 2012)

4. ## Re: Stacks (evaluating postfix expression)

Originally Posted by helloworld922
From Wikipedia:

Operations which are non-commutative are still written in "conventional order", i.e.:

a b op = a op b

4 2 / = 4 / 2 = 2
2 4 / = 2 / 4 = 0.5
So I guess 36 is right, thanks