#include "iostream"
template<class Type>
stack<Type>::stack(int s):top(-1),maxsize(s){
element=new Type[maxsize];
}
template<class Type>
void stack<Type>::push(const Type & item){
if(isfull()==1)
exit(0);
else
element[++top]=item;
}
template<class Type>
Type stack<Type>::pop(){
if(isempty()==0)
exit(0);
return element[top--];
}
template<class Type>
Type stack<Type>::getpop(){
if(isempty()==0)
exit(0);
else
return(element[top]);
}
"#ifndef STACK_H
#define STACK_H
template<class Type> class stack
{public:
stack(int =30);
~stack(){delete[] element;}
void push(const Type &item);
Type pop();
Type getpop();
void makeempty(){top=-1;}
int isfull() const{
if(top==maxsize-1)
return 1;
else
return 0;
}
int isempty() const
{if (top==-1)
return 0;
else
return 1;
}
private:
Type* element;
int maxsize;
int top;
};
#endif
using namespace std;
void value(stack<double>& );
void DoOperand(char op,stack<double>& );
int main()
{stack<double>mystack(20);
value(mystack)
cout<<"输出表达式"<<endl;
return 0;}
int DoOperand(char op,stack<double>& ){
}double x;double y;
if (mystack.IsEmpty())
{
cerr<<"Missing Operand!"<<endl; return -1;
}
x=mystack.Pop();
if(mystack.IsEmpty()){
cerr<<"Missing Operand!"<<endl; return -1;
}
y=mystack.Pop();
return 0;
}
switch(op){
case'+': mystack.Push(x+y);break;
case'-': mystack.Push(x-y);break;
case'*': mystack.Pushx*y);break;
case'/': if(x==0.0){
cerr<<"Divide by 0!"<<endl; Clear();
}
elses.Push(x/y;break;
case'^': mystack.Push(Power(x,y);break;
}
else mystack.MakeEmpty;
}
void value(stack<double>& )
char ch;double x,y;
while(cin>>ch,ch!='='){
swith(ch){
case'+':case'-':case'*':case'/':case'^':
DoOperator(ch);break;
default:cin.putback(ch);
{ cin.putback(ch);
cin>>x;
if(y==1)
{ y=0;
mystack.push(x*(-1.0));
}
else
{mystack.push(x);
break;
}
}
}