# Infix to Postfix

Page 1 of 1

## 8 Replies - 1966 Views - Last Post: 10 February 2012 - 06:00 PM

### #1 lina29

Reputation: 0
• Posts: 15
• Joined: 29-September 10

# Infix to Postfix

Posted 06 February 2012 - 07:24 PM

Show the content of the stack, after each step, when evaluating the postfix ex- pression:
8 2 + 6 4 + 3 * 3 4 + 3 * + *
Each digit represents a number, so 8 2 means 8 and 2 (two numbers), and 8 2 + means 8+2 in infix. What is the final value?

I believe I have this right I just want someone to double-check it

8 2 (where 8 is at the bottom of the stack)
10
10 6 4
10 10
10 10 3
10 30
10 30 3 4
10 30 7
10 30 7 3
10 30 21
10 51
510

Is This A Good Question/Topic? 0

## Replies To: Infix to Postfix

### #2 illuss

Reputation: 4
• Posts: 63
• Joined: 14-April 11

## Re: Infix to Postfix

Posted 06 February 2012 - 07:38 PM

it looks correct to me.

### #3 lina29

Reputation: 0
• Posts: 15
• Joined: 29-September 10

## Re: Infix to Postfix

Posted 06 February 2012 - 08:33 PM

Show the content of the stack, after each step, when converting the following infix expression to postfix:
((3 + 2) ∗ 4) + (2 ∗ (2 + 5) ∗ (3 + 4))

I got 3 2 + 4 * 2 2 5 + 3 4 + * * +

Is that correct?

### #4 blackcompe

• D.I.C Lover

Reputation: 1159
• Posts: 2,547
• Joined: 05-May 05

## Re: Infix to Postfix

Posted 06 February 2012 - 08:37 PM

No. There are infix to postfix calculators out there to help check your work. To be honest, I didn't get what the calculators got either.

This post has been edited by blackcompe: 06 February 2012 - 08:47 PM

### #5 lina29

Reputation: 0
• Posts: 15
• Joined: 29-September 10

## Re: Infix to Postfix

Posted 06 February 2012 - 09:26 PM

What did you get? Where did I go wrong? I used the infix to postfix calculators but they showed different answers

### #6 smohd

• Critical Section

Reputation: 1824
• Posts: 4,627
• Joined: 14-March 10

## Re: Infix to Postfix

Posted 06 February 2012 - 09:33 PM

### #7 blackcompe

• D.I.C Lover

Reputation: 1159
• Posts: 2,547
• Joined: 05-May 05

## Re: Infix to Postfix

Posted 06 February 2012 - 09:56 PM

I actually think yours is right. I haven't done this kind of stuff in a while and I didn't follow any algorithm, so excuse what I said before. All of the on-line calculators generate a result different from yours, but I'd just assume yours is right.

((3 + 2) ∗ 4) + (2 ∗ (2 + 5) ∗ (3 + 4)) =>

3 2 + 4 * 2 2 5 + 3 4 + * * +

Evaluation:

[3 2 +] 4 * 2 2 5 + 3 4 + * * +
[5] 4 * 2 2 5 + 3 4 + * * +
[5 4 *] 2 2 5 + 3 4 + * * +
[20] 2 2 5 + 3 4 + * * +
20 2 [2 5 +] 3 4 + * * +
20 2 [7] 3 4 + * * +
20 2 7 [3 4 +] * * +
20 2 7 [7] * * +
20 2 [7 7 *] * +
20 2 [49] * +
20 [2 49 *] +
20 [98] +
[20 98 +]
[118]

### #8 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 12366
• Posts: 45,479
• Joined: 27-December 08

## Re: Infix to Postfix

Posted 07 February 2012 - 06:55 AM

*Moved to Student Campus*

### #9 ishkabible

• spelling expret

Reputation: 1747
• Posts: 5,898
• Joined: 03-August 09

## Re: Infix to Postfix

Posted 10 February 2012 - 06:00 PM

Quote

No. There are infix to postfix calculators out there to help check your work. To be honest, I didn't get what the calculators got either.

there are multiple ways to express the same expression and different algorithms will produce different results hence if you do it intuitively you are likely to get different results

((3 + 2) ∗ 4) + (2 ∗ (2 + 5) ∗ (3 + 4))

I looked at the inner most parts first:
3 2 + for (3 + 2)
2 5 + for (2 + 5)
3 4 + for (3 + 4)

then I looked at the next level(parenthesis are to show original groups):
(3 2 +) 4 * for ((3 + 2) ∗ 4)
(2 5 +) (3 4 +) 2 * * for (2 ∗ (2 + 5) ∗ (3 + 4))

then I just had to put those together with the last operator:
((3 2 +) 4 *) ((2 5 +) (3 4 +) 2 * *) +
or without the grouping
3 2 + 4 * 2 5 + 3 4 + 2 * * +

the only difference I see is that you pushed the first '2' for (2 ∗ (2 + 5) ∗ (3 + 4)) before I did but it's the same either way. your way is what the shunting yard algorithm would make.

This post has been edited by ishkabible: 10 February 2012 - 06:06 PM