427240459 by Unknown

427240459 by Unknown

Author:Unknown
Language: eng
Format: epub


Enter an expression in postfix form:

4 2 $ 3 * 3 - 8 4 / 1 1 + / +

The Prefix expression is:

+ - * $ 4 2 3 3 / / 8 4 + 1 1

In this program the structure postfix contains character arrays like str3 to store the intermediate results. The character arrays stack and target are used to maintain the stack and to store the final string in the prefix form respectively.

In the convert() function the string containing expression in postfix form is scanned through a while loop till the string target is not exhausted. Following steps are performed depending on the type of character scanned.

(a) If the character scanned is a space then that character is skipped.

(b) If the character scanned contains a digit or an alphabet, it is pushed to the stack by calling push() function.

(c) If the character scanned contains an operator, then the topmost two elements are popped from the stack. These two elements are then stored in the array A temporary string temp2 containing the operator and the two operands is formed. This temporary string is then pushed on the stack.

The converted prefix form is stored at the position in the stack. Finally, the show() function displays this prefix form. The steps performed in the conversion of a sample postfix expression 4 2 $ 3 * 3 - 8 4 / 1 1 + / + to its equivalent prefix expression is shown in Table



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.