?? bstack.h
字號:
#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 + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -