func3-2.c
来自「一些数据结构的基本算法」· C语言 代码 · 共 74 行
C
74 行
/* func3-2.c algo3-6.c和algo3-7.c要调用的函数 */
char Precede(SElemType t1,SElemType t2)
{ /* 根据教科书表3.1,判断t1,t2两符号的优先关系('#'用'\n'代替) */
char f;
switch(t2)
{
case '+':
case '-':if(t1=='('||t1=='\n')
f='<'; /* t1<t2 */
else
f='>'; /* t1>t2 */
break;
case '*':
case '/':if(t1=='*'||t1=='/'||t1==')')
f='>'; /* t1>t2 */
else
f='<'; /* t1<t2 */
break;
case '(':if(t1==')')
{
printf("括号不匹配\n");
exit(ERROR);
}
else
f='<'; /* t1<t2 */
break;
case ')':switch(t1)
{
case '(':f='='; /* t1=t2 */
break;
case'\n':printf("缺乏左括号\n");
exit(ERROR);
default :f='>'; /* t1>t2 */
}
break;
case'\n':switch(t1)
{
case'\n':f='='; /* t1=t2 */
break;
case'(' :printf("缺乏右括号\n");
exit(ERROR);
default :f='>'; /* t1>t2 */
}
}
return f;
}
Status In(SElemType c)
{ /* 判断c是否为7种运算符之一 */
switch(c)
{
case'+' :
case'-' :
case'*' :
case'/' :
case'(' :
case')' :
case'\n':return TRUE;
default :return FALSE;
}
}
SElemType Operate(SElemType a,SElemType theta,SElemType b)
{ /* 做四则运算a theta b,返回运算结果 */
switch(theta)
{
case'+':return a+b;
case'-':return a-b;
case'*':return a*b;
}
return a/b;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?