C++栈实现

来源:互联网 发布:淘宝怎样增加访客量 编辑:程序博客网 时间:2024/06/05 15:11
#include<iostream>
using namespace std;
template<class T>
class Stack
{
private:
enum{max = 5};
T arr[max];
int top;
public:
Stack() :top(0){}
int get_max()
{
return max;
}
Stack& Push(T d)
{
if (Full())
{
cout << "栈已满!" << endl;
exit(1);
}
arr[top++] = d;
return *this;
}
T Pop(T d)
{
return d;
}
bool Full()
{
if (top >= max)
{
return true;
}
return false;
}
bool Empty()
{
if (top == 0)
{
return true;
}
return false;
}
void travel()
{
for (int i = top-1; i >= 0; i--)
{
cout << arr[i] << endl;
}
}
void clear()
{
top = 0;
}
};
int main()
{

cin.get();
return 0;
}
0 0