对顶栈的设计

来源:百度知道 编辑:UC知道 时间:2024/06/23 14:53:36
我是初级选手,没学过C++,只接触C语言和数据
是“对顶栈”

#include<iostream.h>
const int maxstack=10;
enum Error_code{success,fail,overflow,underflow};
template < class entry_stack>
class stack
{private:
int count;
entry_stack entry[maxstack];
public:
stack();
bool empty()const;
Error_code push(const entry_stack &item);
Error_code pop();
entry_stack top();
};
template <class entry_stack>
stack<entry_stack>::stack()
{count=0;}
template <class entry_stack>
bool stack<entry_stack>::empty()const
{
return(count==0);
}
template<class entry_stack>
Error_code stack<entry_stack>::pop()
{if(empty()) return underflow;
count--;
return success;
}
template <class entry_stack>
Error_code stack<entry_stack>::push(const entry_stack &item)
{if(count==maxstack)return overflow;
entry[count++]=item;
return success;
}