answersLogoWhite

0

Algorithm to Convert Infix to Prefix Form

Suppose A is an arithmetic expression written in infix form. The algorithm finds equivalent prefix expression B.

Step 1. Push ")" onto STACK, and add "(" to end of the A

Step 2. Scan A from right to left and repeat step 3 to 6 for each element of A until the STACK is empty

Step 3. If an operand is encountered add it to B

Step 4. If a right parenthesis is encountered push it onto STACK

Step 5. If an operator is encountered then:

a. Repeatedly pop from STACK and add to B each operator (on the top of STACK) which has same or higher precedence than the operator.

b. Add operator to STACK

Step 6. If left parenthesis is encontered then

a. Repeatedly pop from the STACK and add to B (each operator on top of stack until a left parenthesis is encounterd)

b. Remove the left parenthesis

Step 7. Exit

User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

What is the time complexity of infix to post fix conversion algorithm?

O(nlogn)


Write an algorithm in c to convert an infix expression to a postfix expressionexecute your algorithm with the following infix expression as your input. m nk pgh a bc?

An algorithm can not be written with the following infix expression without knowing what the expression is. Once this information is included a person will be able to know how to write the algorithm.


What are the three kinds of affixes?

Prefix, suffix and infix


Program to convert infix to prefix?

I dont have the idea about the program but I know that prefix means the first starting letters of a particular things. I really think so there is a progam to convert infix to prefix but i might have misunderstood your question can you make it little simpler please.


Convert infix to prefix to postfix?

(a + b) * c / ((x - y) * z)


What is prefix expression?

Example: prefix: * 2 + 3 4 infix: 2 * (3+4) postfix: 2 3 4 + *


Prefix suffix and infix examples with meaning and word definition?

An example of a prefix in the English language is pre, meaning before. An example of a suffix would be ing, meaning a verbal action. An example of an infix would be ful, meaning full of.


Which data structure convert logical to physical address?

Linear data structure is used to convert the logical address to physical address .Stack is used in this and the various conversion such as postfix,prefix and infix notation are come in this


Algorithm for conversion from prefix to infix?

The belt-and-braces technique is easy enough: > > prefix_to_infix(stream, stack) > if stack is not empty > pop a node off the stack > if this node represents an operator > write an opening parenthesis to stream > prefix_to_infix(stream, stack) > write operator to stream > prefix_to_infix(stream, stack) > write a closing parenthesis to stream > else > write value to stream > endif > endif > endfunc


Who invented postfix and infix?

infix: old Egyptians/Assirs some thousands year before prefix: Jan Łukasiewicz (Polish Notation) postfix: Burks, Warren, and Wright (Reverse Polish Notation)


What are the prefixes and suffixes in punctual compared to the prefixes and suffixes in punctilitous?

The prefix in "punctual" is "pun-" and the suffix is "-ual". In "punctilious", the prefix is "pun-", the infix is "-ctil-", and the suffix is "-ious".


Prefix to postfix conversion using C programming?

#include<stdio.h> #include<conio.h> #include<string.h> char symbol,s[10]; int F(symbol) { switch(symbol) { case '+': case '-':return 2; case '*': case '/':return 4; case '^': case '$':return 5; case '(':return 0; case '#':return -1; default :return 8; } } int G(symbol) { switch(symbol) { case '+': case '-':return 1; case '*': case '/':return 3; case '^': case '$':return 6; case '(':return 9; case ')':return 0; default: return 7; } } void infix_to_postfix(char infix[],char postfix[]) { int top=-1,j=0,i,symbol; s[++top]='#'; for(i=0;i<strlen(infix);i++) { symbol=infix[i]; while(F(s[top])>G(symbol)) { postfix[j]=s[top--]; j++; } if(F(s[top])!=G(symbol)) s[++top]=symbol; else top--; } while(s[top]!='#') { postfix[j++]=s[top--]; } postfix[j]='\0'; } void main() { char infix[30],postfix[30]; clrscr(); printf("Enter the valid infix expression\n"); scanf("%s",infix); infix_to_postfix(infix, postfix); printf("postfix expression is \n %s", postfix); getch(); }