-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathINTOPO.BAK
More file actions
67 lines (63 loc) · 1.12 KB
/
INTOPO.BAK
File metadata and controls
67 lines (63 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define max 20
char stack[max];
int top=-1;
void push(char x)
{
if(top==(max-1))
printf("overflow of stack");
else
stack[++top]=x;
}
char pop()
{
if(top==-1)
{ printf("underflow of stack");
return -1 ;
}
else
{
return(stack[top--]);
}
}
int priority(char x)
{
if(x=='(') return 0;
else if(x=='+'|| x=='-') return 1;
else if(x=='*'|| x=='/') return 2;
else return -1;
}
void main()
{ int i,l,t1,t2;
char exp[10];
clrscr();
printf("Enter the infix expression\n");
scanf("%s",exp);
l=strlen(exp);
exp[l]=')';
push('(');
for(i=0;i<=l;i++)
{
if( (exp[i] >=97 && exp[i]<122) ||(exp[i] >=65 && exp[i]<90))
{
printf("%c",exp[i]);
}
else if(exp[i]=='(')
push(exp[i]);
else if(exp[i]==')')
{ while(stack[top]!='(')
printf("%c",pop());
pop();
}
else
{ t1=priority(stack[top]);
t2=priority(exp[i]);
while(t1>t2 && stack[top]!='(')
printf("%c",pop());
push(exp[i]);
}
}
getch();
}