C++算术表达式求解

2014-10-30 13:00:06 · 作者: · 浏览: 59

  操作数支持:多位数,小数


  运算符支持:+ - * / ( )


  #include


  #include


  #include


  /*栈*/


  template


  class CStack


  {


  public:


  int m_count;


  T * m_arr;


  int m_curposition;


  CStack(int count)


  {


  m_arr = new T [count];


  m_count = count;


  m_curposition = -1;


  }


  bool push(T val)


  {


  if(m_curposition == m_count-1)


  return false;


  m_arr[++m_curposition] = val;


  }


  T pop()


  {


  if(IsEmpty())


  return 0;


  return m_arr[m_curposition--];


  }


  T GetElement()


  {


  if(IsEmpty())


  return 0;


  return m_arr[m_curposition];


  }


  bool IsEmpty()


  {


  if(m_curposition < 0)


  return true;


  return false;


  }


  ~CStack()


  {


  delete [] m_arr;


  }


  };