Thread: Writing in postfix notation

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    155

    Writing in postfix notation

    For a lab we must convert an infix expression to a postfix one that is devoid of parentheses.

    Like if I entered (3 + 5) the postfix expression is 35+

    However, what if I do (19 + 2)? It certainly is not 192+, for that would make 111, which just... isn't right. And we can't do (19)2+ I assume because the problem clearly states that parenthesis cannot be used. What's the official way, here?

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    You're probablly reading the problem wrong. You can't do what you want to do.

    EDIT: You are talking about compile-time, right? Or are you saying that you want someone to input something through IO? You can't overload operators to make 35+ do 3 + 5 because there is no postfix operator +

    If you mean via IO then I don't see what the problem is. Just use a space.
    Last edited by Polymorphic OOP; 11-30-2002 at 10:23 PM.

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    155
    I think you misread the question

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    155
    The user inputs a string of an infix expression and the equation inputted into the string is converted to postfix and evaluated

  5. #5
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    why not just put spaces or commas in between the numbers? so 3+5 -> 3,5+ or 3 5+, and 19 + 2 -> 19,2+ or 19 2+
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  6. #6
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Yeah, like i said

    35+

    is not a postfix addition expression because it has only one operand

    you have to separate them by spaces.

    IE

    3 5 +

  7. #7
    Registered User
    Join Date
    Oct 2002
    Posts
    155
    Ah, I see :P

    Yeah, in our class 3 + 5 is written as 35+

  8. #8
    Registered User
    Join Date
    Aug 2002
    Posts
    14
    Well what you can do is enter all those character into a char array infix, then convert it into a postfix expression and put it into char array postfix, then evaluate that postfix expression using the postfix array.

    I did the same thing, and I used a Stack data structure to solve it, with a dynamic char array to hold my postfix expression.

    Also you need to put spaces netween your postfix expression, because it makes it easier to read, for example:

    192+ --> is this (19 + 2) or (1 + 92) ?

    so you write it:

    19 2 +

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Expression: Convert infix notation to postfix notation.
    By Nutshell in forum C Programming
    Replies: 7
    Last Post: 02-27-2010, 07:44 AM
  2. Postfix (reverse polish notation) calculator
    By ottomated in forum C Programming
    Replies: 7
    Last Post: 05-06-2008, 05:32 PM
  3. Replies: 4
    Last Post: 03-12-2006, 02:17 PM
  4. stack (array impl) problem: postfix notation
    By kocika73 in forum C Programming
    Replies: 2
    Last Post: 04-17-2005, 01:35 PM
  5. Postfix Notation Calculator
    By C Student in forum C Programming
    Replies: 3
    Last Post: 12-01-2002, 01:01 PM