/* 后缀表达式计算 中缀表达式转后缀表达式 */ #include<iostream> #include<cstdlib> #include<cctype> using namespace std; template<class T> class stack { private: T* base; T* top; int stackSize; public: stack(int a=100):stackSize(a) { base=top=new T[stackSize]; } ~stack() { delete [] base; base=top=NULL; cout<<"stack析构 "; } bool is_empty()const; bool is_full()const; bool pop(T &a); bool push(T a); int len()const; }; template<class T> bool stack<T>::is_empty()const { if(base==top) return true; else return false; } template<class T> bool stack<T>::is_full()const { if(top-base==stackSize) return true; else return false; } template<class T> bool stack<T>::push(T a) { if(!is_full()) { *(top++)=a; return true; } else return false;; } template<class T> bool stack<T>::pop(T& a) { if(!is_empty()) { a=*(--top); return true; } else return false; } template<class T> int stack<T>::len()const { cout<<(int*)base<<endl; cout<<(int*)top<<endl; return top-base; } double postfix(char* str) // 计算后缀表达式 { char c; stack<double>s; char bluff[10]; int j=0; c=str[j++]; while(c!='#') { int i=0; while(isdigit(c) || c=='.')//处理的数是double型的 { bluff[i++]=c;// 用一块缓存区存储char型数据后转换 if(i>=10) { printf(" 输入的数过大 "); return 1; } c=str[j++]; if(' '==c) // 处理数字后的空格,符号后的空格不管 { bluff[i]='