【发布时间】:2016-01-22 06:36:41
【问题描述】:
我明天有一个任务,我刚刚开始。
我被要求使用链表做一个 RPN 计算器。
我的想法是我必须编写一个输入字符串,例如 (25 35 +),然后使用链表显示结果。
使用的结构是
typedef struct {
int data;
struct cell *next;}cell;
和
typedef struct {
int positif;
struct cell *datas;
int ref;} num ;
在上面的例子中,当我写 25 35 + 时,我必须将 25 作为一个数字存入堆栈,并且对 35 执行相同的操作,当读取操作符时,我执行操作呼叫 2 个 pop。
问题是我不知道如何在读取空格时将数字与字符串分开。
这是我的主线
char strIn[250];
num *lenumero = initialisation();
printf(">");
scanf("%s", &strIn);
int i=0;
while(strIn[i] != '\0')
{
/*Here I want to write the code that reads the string untill it finds a space ,
然后它将空间前的数字压入堆栈!
}
例如 StrIn[0]=2 STrIn[1]=5 strIn[2]=(空格) 所以我将2放入一个cell->data,5放入cell->next->data,然后我将所有的cell放入结构编号使用的cell中,并将结构编号压入栈中。
谢谢
【问题讨论】:
-
逆波兰表示法?
-
@erip,把反向波兰表示法称为 PRN 真是个绝妙的笑话!
-
字符串
( 25 35 + )不是有效的后缀表示法。后缀中没有括号。
标签: c stack calculator postfix-notation