answersLogoWhite

0

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

User Avatar

Wiki User

∙ 15y ago
User Avatar

What else can I help you with?

Related Questions

Program to convert a infix expression in to postfix and prefix expression in php?

To convert an infix expression to postfix and prefix in PHP, you can implement the Shunting Yard algorithm for postfix conversion and a modified approach for prefix conversion. For postfix, you use a stack to reorder operators based on their precedence and associativity while scanning the infix expression. For prefix, you can reverse the infix expression, convert it to postfix, and then reverse the resulting postfix expression. Here’s a brief code outline for both conversions: function infixToPostfix($infix) { // Implement the Shunting Yard algorithm to convert infix to postfix } function infixToPrefix($infix) { // Reverse the infix expression // Convert to postfix using infixToPostfix // Reverse the postfix result to get prefix } You would need to handle operators, parentheses, and precedence rules within these functions.


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


Algorithm for infix to prefix conversion?

Basically, the shunting algorithm (infix to postfix) works like this (I'm writing this from memory, BTW, so I apologize in advance for any mistakes):1. You create a stack and an output string.2. Then you read the infix string one token at a time; each token is either an identifier or an operator:a. If the token is an identifier (eg, a variable or a constant), then you append it onto the end of the output string.b. If the token is an operator, then you compare its precedence with the precedence of the operator on the top of the stack.i. If the operator on the top of stack has lower precedence, then push the new operator onto the stack.ii. Else, pop the operator from the top of stack and append it to the output string. Then push the new operator onto the stack.otherwisec. If the token is an open parenthesis, then push it onto the stack.d. If the token is a close parenthesis, then pop and append the operators from the stack until the open parenthesis is popped. Discard both parentheses.Google for "shunting algorithm" for a more detailed and better better description. You might also find reference to an algorithm for converting infix to prefix.Algorithm_for_infix_to_prefix_conversionrefer this page for your question.....


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)


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


What is prefix expression?

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


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)


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(); }