#include<stdio.h>
#include<conio.h>
#define MAX 30
typedef struct stack
{
char stk[MAX];
int top;
}
STACK;
void init_stack(STACK *sp)
{
sp->top=-1;
}
int is_empty(STACK *sp)
{
return sp->top==-1;
}
void push(STACK *sp,char val)<
{
sp->stk[++sp->top]=val;
}
char pop(STACK *sp)
{
return sp->stk[sp->top--];
}
char peek(STACK *sp)
{
return sp->stk[sp->top];
}
void disp(STACK *sp)
{
int i;
for(i=0;i<=sp->top;i++)
printf("%c",sp->stk[i]);
printf("\n");
}
int priority(char opr)
{
switch(opr)
{
case '^': return 1;
case '*':
case '/': return 2;
case '+':
case '-': return 3;
default: return 4;
}
}
int is_oper(char c)
{
return c=='+'||c=='-'||c=='*'||c=='/'||c=='^';
}
void in_post(char in[], char post[])
{
STACK opstk;
char symb,topsymb;
int i,j=0;
init_stack(&opstk);
printf("symb\t\tpostfix\t\topstk\n");
for(i=0;in[i]!='\0';i++)
{
symb = in[i];
if(is_oper(symb))
{
while(!is_empty(&opstk) &&
priority(peek(&opstk))<=priority(symb))
post[j++] = pop(&opstk);
push(&opstk,symb);
}
else if(symb== ')')
{
topsymb = pop(&opstk);
while((topsymb=pop(&opstk))!='(')
post[j++]=topsymb;
}
else if(symb == '(')
push(&opstk,symb);
else
post[j++]=symb;
printf("%c\t\t%s\t\t",symb,post);
disp(&opstk);
}
while(!is_empty(&opstk))
{
post[j++]=pop(&opstk);
printf("\t\t%s\t\t",post);
disp(&opstk);
}
}
void main()
{

char infix[MAX],postfix[MAX]="";
clrscr();
printf("Enter a infix epression:");
scanf("%s",infix);
in_post(infix,postfix);
printf("Postfix expression: %s",postfix);
getch();
}

Output-
Enter the Infix Expression : A*(B+D)/E-F*(G+H/K)
the PostFix Expression is : A*BD+E/F*-GHK/+

Search

Project Categories

Recent Posts

Mail Management System
Posted on 2019-07-18
Online food ordering system
Posted on 2019-07-18
Library Management System
Posted on 2019-07-17
Health center system project
Posted on 2019-07-17
Gym Management System
Posted on 2019-07-17
furniture management system
Posted on 2019-07-17
Electronic shop management system
Posted on 2019-07-17
Automobile Workshop Management
Posted on 2019-07-17
Online Visa Processing System
Posted on 2019-07-17
Inventory management System
Posted on 2019-07-17
petrol-management system
Posted on 2019-07-17
Cloths management system
Posted on 2019-07-17
Society Management system
Posted on 2019-07-17
Mall management system
Posted on 2019-07-17
school management system
Posted on 2019-07-17
Sales Order Processing System
Posted on 2019-07-17
Retail sales management
Posted on 2019-07-17
Raw Materials Management
Posted on 2019-07-17
railway reservation system
Posted on 2019-07-17
purchase and sales management system
Posted on 2019-07-17
Placement Management System
Posted on 2019-07-17
Pet Shop Management System
Posted on 2019-07-17
petrol pump management system
Posted on 2019-07-17
Patient Information System
Posted on 2019-07-17
news agency system
Posted on 2019-07-17
Cinema Booking System
Posted on 2019-07-17
Medical Store System
Posted on 2019-07-17
leave management System
Posted on 2019-07-17
Laboratory Information Management System
Posted on 2019-07-17
content management system
Posted on 2019-07-17
Inventory management System
Posted on 2019-07-17
Institute Management System
Posted on 2019-07-17
Hotel management System
Posted on 2019-07-17
Gym Management System
Posted on 2019-07-17
Garage Management System
Posted on 2019-07-17
Furniture shop management system
Posted on 2019-07-17
Fisheries management  System
Posted on 2019-07-17
Fertilizer scheduling system
Posted on 2019-07-17
online eye care system
Posted on 2019-07-17
Dental Clinic Management System
Posted on 2019-07-17
Cyber Café Management
Posted on 2019-07-17
Milk Billing System
Posted on 2019-07-17
Colddrink management system
Posted on 2019-07-17
Cable management System
Posted on 2019-07-17
Beauty parlor management system
Posted on 2019-07-17
Facebook Clone
Posted on 2019-05-28
Dance Class Management System
Posted on 2019-05-24
Library Management System
Posted on 2019-05-24
Cab Management System
Posted on 2019-05-23
Blood Bank Management system
Posted on 2019-05-23
Beauty Parlour Management System
Posted on 2019-05-23
vissa proccesing system
Posted on 2019-05-23
Toll Plazza
Posted on 2019-05-23
BILLING APPLICATION
Posted on 2019-05-23
FLORICULTURE MANAGEMENT SYSTEM
Posted on 2019-05-23
Car On Rent
Posted on 2019-05-23
E-commers Shop
Posted on 2019-05-23

Sign In