# - Write a program to convert an infix expression to a postfix expression?

// made by vijay NITJ

#include<iostream.h>

#include<string.h>

#include<stdio.h>

#include<math.h>

int precedence(char);

void main()

{

char q[20];

char p[20];

char stack[20];

int tp=-1,ts=0;

stack[0]='(';

cout<<stack;

int i=0, f=1;

cout<<"enter the prefix expression ";

gets(q);

int l=strlen(q);

q[l]=')';

while(ts!=-1)

{

if(q[i]>=47 && q[i]<=58 q[i]<=65 && q[i]<=90 q[i]<=97 && q[i]>=122)

{

p[++tp]=q[i];

}

else if(q[i]=='(')

stack[++ts]=q[i];

else if(q[i]=='+' q[i]=='-' q[i]=='*' q[i]=='/')

{

if(stack[ts]=='(')

stack[++ts]=q[i];

else

{

while(stack[ts]!='(')

{

int p1=precedence(q[i]);

int p2=precedence(stack[ts]);

if(p2>=p1)

p[++tp]=stack[ts--];

else

{

f=0;

break;

}

}

if(f==0)

stack[++ts]=q[i];

}

}

else if(q[i]==')')

{

while(stack[ts]!='(')

{

p[++tp]=stack[ts--];

}

ts--;

}

i++;

}

for(int j=0; j<=tp;j++)

{

cout<<p[j];

}

//precedence program

int precedence(char a)

{

if(a=='+' a=='-')

return 1;

else if(a=='*' a=='/')

return 2;

}

### Why do compilers convert infix expressions to postfix?

people almost exclusively use infix notation to write mathematical expressions, computer languages almost exclusively allow programmers to use infix notation. However, if a compiler allowed infix expressions into the binary code used in the compiled version of a program, the resulting code would be larger than needed and very inefficient. Because of this, compilers convert infix expressions into postfix notation expressions, which have a much simpler set of rules for expression evaluation. Postfix notation gets…

### Write a program in C language to convert infix expression to postfix expression?

# /**************************/ /**********cReDo**********/ /*****mchinmay@live.com***/ //C PROGRAM TO CONVERT GIVEN VALID INFIX EXPRESSION INTO POSTFIX EXPRESSION USING STACKS. #include<stdio.h> #include<conio.h> #include<string.h> #define MAX 20 char stack[MAX]; int top=-1; char pop(); void push(char item); int prcd(char symbol) { switch(symbol) { case '+': case '-':return 2; break; case '*': case '/':return 4; break; case '^': case '$':return 6; break; case '(': case ')': case '#':return 1; break; } } int isoperator(char symbol) { switch(symbol) { case '+': case…

### Write an algorithm to convert infix expression into postfixexpression?

Infix Expression : Any expression in the standard form like "2*3-4/5" is an Infix(Inorder) expression. Postfix Expression : The Postfix(Postorder) form of the above expression is "23*45/-". Infix to Postfix Conversion : In normal algebra we use the infix notation like a+b*c. The corresponding postfix notation is abc*+. The algorithm for the conversion is as follows : Scan the Infix string from left to right. Initialise an empty stack. If the scannned character is an…

### HOW TO SOLVE 'C' problem?

1. write a 'c' program to read 4(four)numbers from a file 'BANK' and calculate the average of the numbers.Now print the calculated average in another output file 'AVERAGE' 2. write a 'c' program that finds the sum and average of inputted five integer numbers of the array using dynamic memory allocation function malloc(). 3. write a 'c' program to create simple elements 1,2,3,4 in the link list of 4(four)nodes and display the list's elements. 4…

### Write a program To implement stack and convert infix to postfix expression?

#include <stdio.h> #include <stdlib.h> #define max 20 typedef enum status_code{failure,success}status_code; typedef struct node_tag { char operator; struct node_tag *next; }node; typedef struct queue { struct node_tag *front; struct node_tag *rear; }queue; void initialise_queue(queue *qptr) { qptr->front=NULL; qptr->rear=NULL; } status_code insert_node(node **lptr,char val)

### Write a program in C language to evaluate a Postfix expression by using a STACK Illustrate the algorithm with the help of an example?

/*A VERY SIMPLE PROGRAM TO EVALUATE POSTFIX EXPRESSION USING STACK */ #include<iostream.h> #include<conio.h> #include<string.h> void main() { int *stack; char *p; int top=0,i=0; clrscr(); cout<<"WELCOME TO THE PROGRAM MADE BY SAURABH GNDU JALANDHAR "<<endl; cout<<""<<endl; cout<<"ENTER THE POSTFIX EXPRESSION "<<endl; cin>>p; int c = strlen(p); while(i<c) { if(!( (p[i]>=42) && (p[i]<=47)) ) { top = top +1; stack[top] = p[i]; stack[top] = stack[top] - 48; //cout<<stack[top]<<endl; } else { int temp1 , temp2; temp1 =…

### How do infix notation and postfix notation differ?

It's simply a matter of where the operators are placed in relation to their operands: infix: X + Y prefix: + X Y postfix: X Y + All of the above are equivalent. Prefix notation is also known as Polish notation, hence postfix is also known as reverse Polish notation. Given the infix equation A * B + C / D, the order of evaluation is always parenthesis, orders, divide/multiply, add/subtract (PODMAS), thus we must…

### How do you write xy in c program?

Assuming that x and y are two variables, such as they might be in Algebra, and that the expression "xy" is meant to be the multiplication of x times y, you would write it as x * y This expression could be used with a third variable in an assignment statement, or as a condition in an if statement where it can be compared to another variable or a constant.

### Write a program to convert a postfix expression to an evaluated value using Stack?

/*Postfix->Evaluated value */ #include <stdio.h> #include<stdlib.h> #include <math.h> #define MAXCOLS 80 #define TRUE 1 #define FALSE 0 struct stack{ int top; double items[MAXCOLS]; }; double eval(char[]); double pop(struct stack *); void push(struct stack *,double); int empty(struct stack *); int isdigit(char); double oper(int,double,double); void main() { char expr[MAXCOLS]; int position =0; while((expr[position++] = getchar()) != '\n') ; expr[--position] = '\0'; printf("%s%s", " the original postfix expression is ",expr); getchar(); printf("\n %f ", eval(expr)); getchar(); } double…

### What is the difference between compiler and editor?

An editor is just a program in which you write and edit the program. The compiler is used to compile the program, i.e., convert the program to machine understandable code. A development environment often combines the both into an intelligent application called the IDE or Integrated Development Environment.