这个程序哪里错了,求大神指教
#include<iostream>using namespace std;
//求表达式
//============================
struct NumberNode
{
float data;
struct NumberNode *next;
};
//定义数据栈
//===========================
struct OPTRNode
{
char ch;
struct OPTRNode *next;
};
//=========================
//操作数栈
void push_number(NumberNode *&s,float x);
void pop_number(NumberNode *&s,float &x);
void create_number(NumberNode *&s);
float GetTop_number(NumberNode *&s);
//===========================
//操作符栈
void push_operator(OPTRNode *&r,char e);
void pop_operator(OPTRNode *&r,char &y);
void create_operator(OPTRNode *&r);
char GetTop_operator(OPTRNode * &r);
//==============================
//==============================
bool ISnumber(char e);
bool ISchar(char e);
char compare(char a1,char a2,char b[5],char c[5][5]);
float evaluate(float a,float b,char op);
float Getnumber(char e);
//=========================
int main()
{
char a,y;
float x1,x2,sum;
char b[5]={'+','-','*','/','#'};
char c[5][5]={
{'>','>','<','<','>'},
{'>','>','<','<','>'},
{'>','>','>','>','>'},
{'>','>','>','>','>'},
{'<','<','<','<','='},
};
//定义运算符优先级集合
NumberNode *s;
create_number(s);
OPTRNode *r;
create_operator(r);
cout<<"请输入一段以'#'结束的表达式!"<<endl;
push_operator(r,'#');
a=getchar();
while(r->next!=NULL)
{
if(ISnumber(a))
{
push_number(s,Getnumber(a));
// a=getchar();
}
else
{
y=GetTop_operator(r);
switch(compare(y,a, b, c))
{
case '<':
push_operator(r,a);
cout<<GetTop_operator(r)<<endl;
// a=getchar();
break;
case '>':
{
pop_operator(r,y);
pop_number(s,x1);
pop_number(s,x2);
sum=evaluate(x1,x2,y);
push_number(s,sum);
// a=getchar();
break;
}
case'=':
cout<<"运算结束!"<<endl;
cout<<GetTop_number(s)<<endl;
exit(1);
}
}
a=getchar();
}
cout<<GetTop_number(s)<<endl;
return 1;
}
//===================================
void push_number(NumberNode *&s,float x)
{
NumberNode *p=new NumberNode;
if(!p)
{
cout<<"内存分配不成功!"<<endl;
exit(1);
}
p->data=x;
p->next=s->next;
s->next=p;
}
//============================
void pop_number(NumberNode *&s,float &x)
{
if(s->next==NULL)
{
cout<<"栈空!"<<endl;
exit(1);
}
NumberNode *p=new NumberNode;
p=s->next;
x=p->data;
s->next=p->next;
delete p;
}
//出栈
//============================
void create_number(NumberNode *&s)
{
s=new NumberNode;
s->next=NULL;
}
//===========================
float GetTop_number(NumberNode *&s)
{
float e;
if(s->next==NULL)
{
cout<<"栈空!"<<endl;
exit(1);
}
e=s->next->data;
return e;
}
//==================================
//============================================
//================================
//操作符栈
void push_operator(OPTRNode *&r,char e)
{
OPTRNode *p=new OPTRNode;
if(!p)
{
cout<<"内存分配不成功!"<<endl;
exit(1);
}
p->ch=e;
p->next=r->next;
r->next=p;
}
//============================
void pop_operator(OPTRNode *&r,char &y)
{
if(r->next==NULL)
{
cout<<"栈空!"<<endl;
exit(1);
}
OPTRNode *p=new OPTRNode;
p=r->next;
y=p->ch;
r->next=p->next;
}
//============================
void create_operator(OPTRNode *&r)
{
r=new OPTRNode;
r->next=NULL;
}
//===========================
char GetTop_operator(OPTRNode *&r)
{
char e;
if(r->next==NULL)
{
cout<<"栈空!"<<endl;
exit(1);
}
e=r->next->ch;
return e;
}
//=======================
//操作符栈
//=============================
bool ISnumber(char e)
{
if(e>=48&&e<=57)
return true;
else
return false;
}
//判断是否是数字
//===============================
bool ISchar(char e)
{
if(e=='+'||e=='-'||e=='*'||e=='/'||e=='#')
return true;
else
return false;
}
//判断是否是运算符
float Getnumber(char e)
{
return(e-48);
}
//将字符转换为数字
//===========================================
char compare(char a1,char a2,char b[5],char c[5][5] )
{
char d;
int i,j,m,n;
for(i=0;i<5;i++)
{
if(b[i]==a1)
m=i;
}
for(j=0;j<5;j++)
{
if(b[j]==a2)
n=j;
}
d=c[m][n];
return d;
}
//比较两个运算符的优先级
//======================================
float evaluate(float a,float b,char op)
{
if(op=='+')
return (a+b);
if(op=='-')
return (a-b);
if(op=='*')
return (a*b);
if(op=='/')
return (a/b);
else
{
cout<<"输入错误,不能运算!"<<endl;
exit(1);
}
}
//定义四种运算