Professional Documents
Culture Documents
Aim:-Write A Program To Implement Infix Expression To Postfix Expression Using Stack
Aim:-Write A Program To Implement Infix Expression To Postfix Expression Using Stack
5608017 Date:-
Algorithms:- POLISH(Q,P)
Q is expression in infix notation.
P is postfix expression.
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<type.h>
#define Max 50
struct infix
{
char target [Max];
char * s, *t;
char stack [Max];
int.top;
}
void int infix(struct infix x);
void set expr(struct infix x,char);
void push(struct infix *;char);
char pop(struct infix *);
void onvert(struct infix *);
void show(struct infix);
void main( )
{
struct infix P;
char expr[Max];
int infix[i];
clrscr ( );
printf(“\n enter the expression in infix from”);
get (expr);
set expr(& P,expr);
convert(& P);
printf(“the postfix expression is”,show(P);
get ch( );
}
void set infix (struct infix *P)
{
P top-1;
If (*pS))= = ( )
{
push (P *(PS));
PS++;
}
if(*(PS) = “*” = = ‘1’
{
if(Ptop ! = 1)
{
opr = pop (P);
while (priority (opr)>priority(*(PS))
{
*(Pt) = opr
P t++;
opr = pop(P);
}
push (P,opr);
push (P1 *(PS);
}
else
push (P; *(PS);
PS++;
}
if ( *(PS = = ‘j’)
{
opr = pop(P);
while(opr);=’c’
}
*(Pt)=opr;
PS++;
opr = pop(P);
}
Ppop(P);
}
PS++;
}
while(Ppop ! ==-1)
char opr= pop(P);
{
*(Pt)=opr;
Pt++;
}
*(Pt)=’10’;
}
int priority ( char( ))
{
if (c==’S’)
return };
if (i== ‘*’//c=’1’//c==’%’)
return z;
else
{
if (c==’+’//c= =’=’)
return i;
else
return;
}
}
void show (struct infix P)
{
printf(“%d”,P.target);
}
OUTPUT:-