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

#1 lina29   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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   User is offline

  • D.I.C Head

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

Re: Infix to Postfix

Posted 06 February 2012 - 07:38 PM

it looks correct to me.
Was This Post Helpful? 0
  • +
  • -

#3 lina29   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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?
Was This Post Helpful? 0
  • +
  • -

#4 blackcompe   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1159
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#5 lina29   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#6 smohd   User is offline

  • Critical Section
  • member icon


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

Re: Infix to Postfix

Posted 06 February 2012 - 09:33 PM

Please stop opening duplicate threads.
*Thread merged*
Was This Post Helpful? 0
  • +
  • -

#7 blackcompe   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1159
  • View blog
  • 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]
Was This Post Helpful? 0
  • +
  • -

#8 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12324
  • View blog
  • Posts: 45,424
  • Joined: 27-December 08

Re: Infix to Postfix

Posted 07 February 2012 - 06:55 AM

*Moved to Student Campus*
Was This Post Helpful? 0
  • +
  • -

#9 ishkabible   User is offline

  • spelling expret
  • member icon





Reputation: 1747
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1