Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/61.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
中缀到后缀,数学函数(sin),C_C_Postfix Notation - Fatal编程技术网

中缀到后缀,数学函数(sin),C

中缀到后缀,数学函数(sin),C,c,postfix-notation,C,Postfix Notation,如何将数学函数(sin)实现到我的简单中缀到后缀转换器 代码来自 它可能的工具,例如sin? 开始表达式将是例如sin(2+3)或sin(3)+3 你能给我举个例子吗 非常感谢你 int pr(char elem) { /* Function for precedence */ switch (elem) { case '#': return 0; case '(': return 1; case '+': case '-': return 2; case '*': c

如何将数学函数(sin)实现到我的简单中缀到后缀转换器

代码来自

它可能的工具,例如sin? 开始表达式将是例如sin(2+3)或sin(3)+3

你能给我举个例子吗

非常感谢你

int pr(char elem) { /* Function for precedence */
 switch (elem) {
 case '#':
  return 0;
 case '(':
  return 1;
 case '+':
 case '-':
  return 2;
 case '*':
 case '/':
  return 3;
 }
}

main() { /* Main Program */
 char infx[50], pofx[50], ch, elem;
 int i = 0, k = 0;
 printf("\n\nRead the Infix Expression ? ");
 scanf("%s", infx);
 push('#');
 while ((ch = infx[i++]) != '\0') {
  if (ch == '(')
   push(ch);
  else if (isalnum(ch))
   pofx[k++] = ch;
  else if (ch == ')') {
   while (s[top] != '(')
    pofx[k++] = pop();
   elem = pop(); /* Remove ( */
  } else { /* Operator */
   while (pr(s[top]) >= pr(ch))
    pofx[k++] = pop();
   push(ch);
  }
 }
.


暂时来说,如果你想到另一个名字
sin
the

int pr(char elem) { /* Function for precedence */
 switch (elem) {
 case '#':
  return 0;
 case '(':
  return 1;
 case '+':
 case '-':
  return 2;
 case '*':
 case '/':
  return 3;
 case '!':
  return 4;
 }
}
执行: 单(2+3):

罪(3)+3


因此,逻辑也是一样的,但您需要更改以处理从单个字符到字符串的输入。

如果您了解hiw中缀到后缀的工作原理,那么您应该不会遇到后缀前缀的问题。我不明白,您能给我一个简单的数学函数示例吗?或参考任何资料?不,我没有发现一元负号的作用方式与sin的作用方式完全相同。你能实现(-5)吗?
int pr(char elem) { /* Function for precedence */
 switch (elem) {
 case '#':
  return 0;
 case '(':
  return 1;
 case '+':
 case '-':
  return 2;
 case '*':
 case '/':
  return 3;
 case '!':
  return 4;
 }
}
Read the Infix Expression ? !(2+3)
Given Infix Expn: !(2+3)  Postfix Expn: 23+!
Read the Infix Expression ? !(3)+3
Given Infix Expn: !(3)+3  Postfix Expn: 3!3+