bstack.h
来自「多进制输出。输入一个非负的10进制数和一个相应的数字」· C头文件 代码 · 共 67 行
H
67 行
#include <iostream>
using namespace std;
const int MAXSTACKSIZE=50;
template <typename T>
class bstack
{
public:
bstack()
{
// T stacklist[MAXSTACKSIZE];
topIndex=-1;
}
void push(const T& item)
{
if(!full())
{
topIndex++;
stacklist[topIndex]=item;
}
else
cout<<"overflowError"<<endl;
}
void pop()
{ if(!empty())
topIndex--;
else
cout<<"underflowError"<<endl;
}
T& top()
{
if(!empty())
return stacklist[topIndex];
else
cout<<"underflowError"<<endl;
}
const T& top() const
{
if(!empty())
return stacklist[topIndex];
else
cout<<"underflowError"<<endl;
}
bool empty() const
{
if(topIndex==-1)
return true;
else
return false;
}
int size() const
{
return (topIndex+1);
}
bool full()const
{
if(topIndex==MAXSTACKSIZE)
return true;
else
return false;
}
private:
T stacklist[MAXSTACKSIZE];
int topIndex;
};
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?