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.
Printable View
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.
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:
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.Code:char *expr (char *ptr, int *value) {
char expr[128] = {0}, *s = ptr;
int a = trans(ptr[0]), b = trans(ptr[1]), dif;