Postfix help!!

This is a discussion on Postfix help!! within the C++ Programming forums, part of the General Programming Boards category; I want to make a stack based Postfix to infix converter. I don't know how to start with it. Presently ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    112

    Postfix help!!

    I want to make a stack based Postfix to infix converter. I don't know how to start with it. Presently I have a class of stack. Thats all.
    Can anybody help me with the algorithm.

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Have a quick look at the first example here, which is for parsing roman numerals (roman numerals are a form of prefixed notation), altho it is in C:

    Parsing

    This just uses a char array, but I suppose you could use a stack the same way. The key is using a "look ahead character" (x+1) in your evaluation of x:

    Code:
    char *expr (char *ptr, int *value) {
    	char expr[128] = {0}, *s = ptr;
    	int a = trans(ptr[0]), b = trans(ptr[1]), dif;
    Obviously you must take care to insure that ptr[1] is not out of bounds, since this reads through the array one char at a time.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

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, 06:44 AM
  2. Replies: 4
    Last Post: 03-12-2006, 01:17 PM
  3. Just a postfix clarification.
    By SlyMaelstrom in forum C++ Programming
    Replies: 3
    Last Post: 12-08-2005, 08:47 AM
  4. Infix to Postfix
    By dat in forum C Programming
    Replies: 6
    Last Post: 06-16-2003, 08:46 AM
  5. postfix
    By datainjector in forum C Programming
    Replies: 11
    Last Post: 11-20-2002, 07:33 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21