express1.c
来自「C语言的一些常用的经典的非常重要的算法(1)」· C语言 代码 · 共 61 行
C
61 行
typedef struct
{
int flag; //0 : operator 1: number
string data;
linktable *father;
linktable *son;
linktable *brother;
}linktable;
string s = '';
Status Output_Expression(linkTable T) //输出存储的表达式
{
linkTable temp;
if(T->flag ==1) //number
{
s += "(";
s += T->data;
temp = T;
while (!T->brother)
{
s += temp->father->data;
s += T->data;
T = T->brother;
}
T = temp;
s += ")";
}
else if(T->flag == 0) //operator
{
if(!T->son) return ERROR; //格式错误
//s += "(";
if(T->son->flag == 0) //operator
{
s += "(";
if(!Output_Expression(T->son)) return ERROR;
s += ")";
}
else if(!Output_Expression(T->son)) return ERROR;
temp = T;
while(!T->brother)
{
s += temp->father->data;
if(T->brother->flag == 0) //operator
{
if(!Output_Expression(T->brother)) return ERROR;
}
else
{
s += T->brother->data;
}
T = T->brother;
}
T = temp;
}
else return ERROR; //非法字符
return OK;
}//Print_Expression
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?