数据结构-习题集答案-(C语言版严蔚敏) 联系客服

发布时间 : 星期一 文章数据结构-习题集答案-(C语言版严蔚敏)更新完毕开始阅读57039dfb9f3143323968011ca300a6c30c22f1d1

}

char Cal(char c1,char op,char c2) {

ch[0]=c2; ch[1]='\\0'; x2=atoi(ch);

switch(op){ case '+':

x=x1+x2; break; x=x1-x2; break; x=x1*x2; break; x=x1/x2; break; break; int x,x1,x2; char ch[10]; ch[0]=c1; ch[1]='\\0'; x1=atoi(ch);

while(Buffer[i]!='#'){ }

return c;

if(!IsOperator(Buffer[i])){ } else{ } i++;

Pop(Opnd,e2); Pop(Opnd,e1);

c=Cal(e1,Buffer[i],e2); Push(Opnd,c); Push(Opnd,Buffer[i]);

ElemType e1,e2;

case '-':

case '*':

case '/':

default:

}

3.23 如题3.21的假设条件,试写一个算法,判断给定的非空后缀表达式是否为正确的逆波兰表达式,如果是,则将它转化为波兰式。

解:

#include #include #include

#include \

typedef char ARRAY[30]; typedef ARRAY ElemType; typedef struct NodeType{

ElemType data; NodeType *next; }

itoa(x,ch,10); return ch[0];

}NodeType,*LinkType; typedef struct{

void InitStack(Stack &s); Status Push(Stack &s,ElemType e); Status Pop(Stack &s,ElemType e); Status IsOperator(char c); Status StackEmpty(Stack s);

Status InvToFroPoland(char a[]);

int main() { }

Status InvToFroPoland(char a[]) {

Stack s; char a[30];

cout<<\请输入逆波兰算术表达式字符序列:\cin>>a;

if(InvToFroPoland(a)) cout<

else cout<<\输入逆波兰算术表达式字符序列错误!\return 0; LinkType top; int size;

}Stack;