-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunc3-1.cpp
67 lines (64 loc) · 1.45 KB
/
func3-1.cpp
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
// func3-1.cpp algo3-5.cpp和algo3-6.cpp要调用的函数
char Precede(SElemType t1,SElemType t2)
{
char f;
switch(t2)
{ case '+':
case '-':if(t1=='('||t1=='\n')
f='<';
else
f='>';
break;
case '*':
case '/':if(t1=='*'||t1=='/'||t1==')')
f='>';
else
f='<';
break;
case '(':if(t1==')')
{ printf("括号不匹配\n");
exit(OVERFLOW);
}
else
f='<';
break;
case ')':switch(t1)
{ case '(':f='=';
break;
case'\n':printf("缺乏左括号\n");
exit(OVERFLOW);
default :f='>';
}
break;
case'\n':switch(t1)
{ case'\n':f='=';
break;
case '(':printf("缺乏右括号\n");
exit(OVERFLOW);
default :f='>';
}
}
return f;
}
Status In(SElemType c)
{
switch(c)
{ case '+':
case '-':
case '*':
case '/':
case '(':
case ')':
case'\n':return TRUE;
default :return FALSE;
}
}
SElemType Operate(SElemType a,SElemType theta,SElemType b)
{
switch(theta)
{ case'+':return a+b;
case'-':return a-b;
case'*':return a*b;
}
return a/b;
}