📄 3.21.txt
字号:
char *RPExpression(char *e)
/* 返回表达式e的逆波兰式 */
{
int i=0,j=0;
char * a,temp;
a=(char*)malloc((strlen(e)+1)*sizeof(char));
Stack s;
InitStack(s);
while(e[i]!='\0'){
switch(e[i]){
case '(': Push(s,e[i]); break;
case ')':{
while(Top(s)!='('){
Pop(s,temp);
a[j++]=temp;
}
Pop(s,temp);
break;
}
case '*':
case '/': {
while(!StackEmpty(s)&&(Top(s)=='/'||Top(s)=='*')){
Pop(s,temp);
a[j++]=temp;
}
Push(s,e[i]);
break;
}
case '+':
case '-':{
while(!StackEmpty(s)&&Top(s)!='('){
Pop(s,temp);
a[j++]=temp;
}
Push(s,e[i]);
break;
}
default : a[j++]=e[i];
}
i++;
}
while(!StackEmpty(s)){
Pop(s,temp);
a[j++]=temp;
}
a[j]='\0';
return a;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -