-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprj2.c
More file actions
59 lines (53 loc) · 1.16 KB
/
Copy pathprj2.c
File metadata and controls
59 lines (53 loc) · 1.16 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
/********************************************************************************
* Name :infix postfix
* Author :Prapanch J
* Description :c- Program
* Version :1.0
* Date :/10/23
* ******************************************************************************/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int top = -1;
char stack[20];
void push(char);
int pop();
int priority(char);
int main() {
push('(');
char infix[20], *p;
printf("Enter the infix expression :\n");
scanf("%s", infix);
p = infix;
printf("\nIt's postfix expression is :\n");
while(*p != '\0') {
if(isalnum(*p))
printf("%c ", *p);
else if(*p == '(')
push(*p);
else if(*p == ')')
while(pop() != '(');
else {
while(priority(stack[top]) >= priority(*p)) {
pop();
}
push(*p);
}
p++;
}
while(top >= 0){
pop();
}
}
void push(char pushElement) {
top++;
stack[top] = pushElement;
}
int pop() {
char x;
x = stack[top];
if(x != '(')
printf("%c ",x);
top--;
return x;
}