#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
class stack
{
public:
stack()
{
s=new char[100];
bottom=0;
top=0;//始终指向栈顶的下一个元素//
}
~stack()
{
delete []s;
}
void push(char c)
{
if(top<=100)
{
s[top]=c;
top=top+1;
}
else
{
cout<<"full stack!"<<endl;
}
}
char pop()
{
top=top-1;
return s[top];
}
bool empty()
{
if(top==bottom)
return true;
else
return false;
}
bool full()
{
if(top>100)
return true;
else
return false;
}
char* shows()
{
return s;
}
int showt()
{
return top;
}
private:
int top;
int bottom;
char *s;
};
void change1()
{
stack s1;//运算符栈//
stack s2;//操作数栈//
char *p=NULL;
s1.push('#');
cout<<"请输入表达式:";
cin>>p;
if(strlen(p)>0)
{
for(int i=0;i<strlen(p);i++)
{
switch(p[i])
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
{
s2.push(p[i]);
break;
}
case ('*'||'+'||'-'||'/'):
{
if((s1.shows())[s1.showt()-1]=='*'||(s1.shows())[s1.showt()-1]=='/')
{
if(p[i]=='+'||p[i]=='/')
{
s2.push(s1.pop());
s1.push(p[i]);
}
else
{
s1.push(p[i]);
}
}
break;
}
case '(':
{
s1.push(p[i]);
}
case')':
{
while((s1.shows())[s1.showt()-1]!=')')
{
s2.push(s1.pop());
}
break;
}
case '#':
{
while((s1.shows())[s1.showt()-1]!=')')
{
s2.push(s1.pop());
}
break;
}
default:break;
}
}
}
cout<<s2.shows()<<endl;
}
void main()
{
change1();
}
运行得了 但是不出结果产生错误,谢谢大家帮我这个忙吧.