什么';在c语言中,分离运算符和数字的最佳方法是什么
我试着建立一个程序,可以通过堆栈计算数字 但是我有一些卡住了。 让我们先看看我的程序是否有效 获取表达式示例(1+2)*3 将其分离并重新排列为“12+3*” 让他们到这个功能,我会它是psudocode什么';在c语言中,分离运算符和数字的最佳方法是什么,c,data-structures,stack,C,Data Structures,Stack,我试着建立一个程序,可以通过堆栈计算数字 但是我有一些卡住了。 让我们先看看我的程序是否有效 获取表达式示例(1+2)*3 将其分离并重新排列为“12+3*” 让他们到这个功能,我会它是psudocode if token is a number push onto the stack else if token is an operator pop operand 1 off the stack pop operand 2 off the stack apply the
if token is a number
push onto the stack
else if token is an operator
pop operand 1 off the stack
pop operand 2 off the stack
apply the operator
push the result back onto the stack
我想要关于如何检查字符串“12+3*”的建议
最好的方法是什么
对不起,我的英语不好
谢谢。我认为您正在尝试计算后缀表达式
4,您只需对整数进行必要的运算。检查字符串,您的意思是什么?如果问题是“如何判断一个字符是数字、运算符还是空格”,答案是
isdigit
和isspace
。我想你已经把空格b/t放在两个数字上了,因为在后缀符号中,两个(或更多个操作数)可以连续出现为AB+
,那么解释器12
(1
、2
)或12
那么您添加空格了吗?
char x = 9; //Character '9' = ASCII 57
int b;
b = x - '0'; //That is '9' - '0' = 57 - 48 = 9
.