-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate link list.c
78 lines (78 loc) · 1.17 KB
/
create link list.c
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
68
69
70
71
72
73
74
75
76
77
78
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#define MAX 100
float st[MAX];
int top=–1;
void push(float st[], float val);
float pop(float st[]);
float evaluatePostfixExp(char exp[]);
int main()
{
float val;
char exp[100];
printf("\n Enter any postfix expression : ");
gets(exp);
val = evaluatePostfixExp(exp);
printf("\n Value of the postfix expression = %.2f", val);
getch();
return 0;
}
float evaluatePostfixExp(char exp[])
{
int i=0;
float op1, op2, value;
while(exp[i] != '\0')
{
if(isdigit(exp[i]))
push(st, (float)(exp[i]–'0'));
else
{
op2 = pop(st);
op1 = pop(st);
switch(exp[i])
{
case '+':
value = op1 + op2;
break;
case '–':
value = op1 – op2;
break;
case '/':
value = op1 / op2;
break;
case '*':
value = op1 * op2;
break;
case '%':
value = (int)op1 % (int)op2;
break;
}
push(st, value);
}
i++;
}
return(pop(st));
}
void push(float st[], float val)
{
if(top==MAX–1)
printf("\n STACK OVERFLOW");
else
{
top++;
st[top]=val;
}
}
float pop(float st[])
{
float val=–1;
if(top==–1)
printf("\n STACK UNDERFLOW");
else
{
val=st[top];
top––;
}
return val;
}