INFIX TO POSTFIX EXPRESSION

1082

bca

infix to ppostfix expression

third semester

program

 

 

#include<stdio.h>
#include<math.h>
char inf[30],postf[30];
int st[30],i=0,j=0,top=-1;
void push(int);
char pop();
main()
{
clrscr();
st[top]=0;
printf(“Enter infix expression : “);
gets(inf);
while(inf[i]!=NULL)
{
switch(inf[i])
{
case ‘(‘:
push(0);
break;
case ‘+’:
while(st[top]>=1)
{
postf[j++]=pop();
}
push(1);
break;
case ‘-‘:
while(st[top]>=1)
{
postf[j++]=pop();
}
push(2);
break;
case ‘*’:
while(st[top]>=3)
{
postf[j++]=pop();
}
push(3);
break;
case ‘/’:
while(st[top]>=3)
{
postf[j++]=pop();
}
push(4);
break;
case ‘^’:
while(st[top]>=5)
{
postf[j++]=pop();
}
push(5);
break;
case ‘)’:
while(st[top]!=0)
postf[j++]=pop();
top–;
break;
default:
postf[j++]=inf[i];
}
i++;
}
while(top>-1)
{
postf[j++]=pop();
}
postf[j]=NULL;
printf(“Postfix expression : “);
puts(postf);
getch();
}
void push(int p)
{
st[++top]=p;
}
char pop()
{
int op;
op=st[top–];
switch(op)
{
case 1:
return ‘+’;
case 2:
return ‘-‘;
case 3:
return ‘*’;
case 4:
return ‘/’;
case 5:
return ‘^’;
}
}

OUTPUT

Enter infix expression : A + (B * C)
Postfix expression : B C * A +

 

if you need a Downloadable link once message us on-page you can get at a time.

m.me/bcanotesnepal

This post is posted for not further third-party purposes.

Copyright By:-  Bcanotesneapl

Not allowed to upload these notes to other sites.

Like our Facebook Page https://www.facebook.com/bcanotesnepal/

if you want to download this PDF comment on us we will provide you a downloadable link.

if you like please share this post with your friend who studies in BCA

if you have any query please comment below,

if you like our sites. you can visit again for the latest updates notes of different BCA subjects of Presentation and different topics with assignment questions and solutions.

Don’t forget to like our page and post also share with your friend and having your group.

if you have any questions you can drop or share them with me using the comment box I will try to answer your question.

Like our Facebook Page https://www.facebook.com/bcanotesnepal/

LEAVE A REPLY

Please enter your comment!
Please enter your name here