关于中缀表达式向后缀表达式转换的编程问题 求解答

BH_Little_Lion 2017-10-26 07:55:26

#include<stdio.h>
#include<string.h>
void PostFix(char *f)
{ char stack[100],x; int i,k,top;
top = 0; stack[0]="#"; i = 0; k = strlen(f);
do {
x = f[i];
switch(x)
{ case ')':
while ((top>0) && (stack[top]!="("))
printf(stack[top--]);
top--; break;
case '+': '-':'*': '/': '^': '%':
while ((top>0) && (isp(stack[top])>=icp(x))
printf(stack[top--]);
stack[++top]=x; break;
default: printf(x) ;}
i=i+1;
}
while (i<=k);
while (top>=0);
printf(stack[top--]);}

int isp(char x) /* 栈内优先级 */

{
int a;
switch(x) {
case '+':a = 1; break;
case '-': a = 1; break;
case '*':
a = 2; break;
case '/':
a = 2; break;
case '%': a = 2; break;
case '^': a = 3; break;
case '(': a = 0; break;
case ')': a = 0; break;
default: a = 0; break; }
return a;}

int icp( char x) /* 栈外优先级 */

{ int a;
switch(x) {
case '+': a = 1; break;
case '-': a = 1; break;
case '*':
a = 2; break;
case '/':
a = 2; break;
case '%': a = 2; break;
case '^': a = 4; break;
case '(': a = 5; break;
case ')': a = 0; break;
default: a = 0; break; }
return a;}

int main()
{ char f[100];
printf("Please enter a char:\n");
gets(f);
PostFix(f);
return 0;
}



打完代码发现好多问题 自己已经debug到这里了
求编程大神解答 ~debug一点是一点。。。
谢谢!

编译器提示错误有5 21 C:\Users\hp\Desktop\中缀表达式向后缀表达式的转换.cpp [Error] invalid conversion from 'const char*' to 'char' [-fpermissive]

10 39 C:\Users\hp\Desktop\中缀表达式向后缀表达式的转换.cpp [Error] ISO C++ forbids comparison between pointer and integer [-fpermissive]

11 28 C:\Users\hp\Desktop\中缀表达式向后缀表达式的转换.cpp [Error] invalid conversion from 'char' to 'const char*' [-fpermissive]

378 15 c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\include\stdio.h [Error] initializing argument 1 of 'int printf(const char*, ...)' [-fpermissive]

13 18 C:\Users\hp\Desktop\中缀表达式向后缀表达式的转换.cpp [Error] expected ';' before ':' token

17 22 C:\Users\hp\Desktop\中缀表达式向后缀表达式的转换.cpp [Error] invalid conversion from 'char' to 'const char*' [-fpermissive]

1 0 C:\Users\hp\Desktop\中缀表达式向后缀表达式的转换.cpp In file included from C:\Users\hp\Desktop\中缀表达式向后缀表达式的转换.cpp

378 15 c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\include\stdio.h [Error] initializing argument 1 of 'int printf(const char*, ...)' [-fpermissive]

22 22 C:\Users\hp\Desktop\中缀表达式向后缀表达式的转换.cpp [Error] invalid conversion from 'char' to 'const char*' [-fpermissive]

1 0 C:\Users\hp\Desktop\中缀表达式向后缀表达式的转换.cpp In file included from C:\Users\hp\Desktop\中缀表达式向后缀表达式的转换.cpp

378 15 c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\include\stdio.h [Error] initializing argument 1 of 'int printf(const char*, ...)' [-fpermissive]

...全文
223 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
BH_Little_Lion 2017-11-10
  • 打赏
  • 举报
回复
我会啦 printf出的错
中缀表达式转换后缀表达式,删除堆栈元素中缀表达式转换后缀表达式,删除堆栈元素中缀表达式转换后缀表达式,删除堆栈元素中缀表达式转换后缀表达式,删除堆栈元素中缀表达式转换后缀表达式,删除堆栈元素中缀表达式转换后缀表达式,删除堆栈元素中缀表达式转换后缀表达式,删除堆栈元素中缀表达式转换后缀表达式,删除堆栈元素中缀表达式转换后缀表达式,删除堆栈元素中缀表达式转换后缀表达式,删除堆栈元素中缀表达式转换后缀表达式,删除堆栈元素中缀表达式转换后缀表达式,删除堆栈元素中缀表达式转换后缀表达式,删除堆栈元素中缀表达式转换后缀表达式,删除堆栈元素中缀表达式转换后缀表达式,删除堆栈元素中缀表达式转换后缀表达式,删除堆栈元素中缀表达式转换后缀表达式,删除堆栈元素中缀表达式转换后缀表达式,删除堆栈元素中缀表达式转换后缀表达式,删除堆栈元素中缀表达式转换后缀表达式,删除堆栈元素中缀表达式转换后缀表达式,删除堆栈元素中缀表达式转换后缀表达式,删除堆栈元素中缀表达式转换后缀表达式,删除堆栈元素中缀表达式转换后缀表达式,删除堆栈元素中缀表达式转换后缀表达式,删除堆栈元素

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧