Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
什么';在c语言中,分离运算符和数字的最佳方法是什么_C_Data Structures_Stack - Fatal编程技术网

什么';在c语言中,分离运算符和数字的最佳方法是什么

什么';在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

我试着建立一个程序,可以通过堆栈计算数字 但是我有一些卡住了。 让我们先看看我的程序是否有效

获取表达式示例(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 operator
 push the result back onto the stack
我想要关于如何检查字符串“12+3*”的建议 最好的方法是什么

对不起,我的英语不好


谢谢。

我认为您正在尝试计算后缀表达式

  • 使用字符数组获取后缀表达式
  • 检查操作员,如果不是操作员u,则必须是操作员 整数
  • 通过使用,可以轻松地将字符整数转换为整数

  • 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
    .