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;
}
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
- c实现顺序栈
- C实现链式栈
- 栈C语言实现
- C语言实现栈
- 栈的C实现
- c实现顺序栈
- C语言实现栈
- C实现栈
- C语言实现栈
- 栈(c实现)
- C语言实现栈
- C语言实现栈
- 【c++】栈的实现
- C代码实现栈
- C链栈实现
- C链式栈实现
- c语言实现栈
- C语言实现栈
- 读书笔记---链接脚本的语法解析
- 第五章 数组和广义表
- C++链表实现
- IM设计思考:XMPP资源绑定
- Eclipse中LogCat不显示的问题
- C++栈实现
- LinearLayout中的layout_weight属性
- 使用d3.js 绘制交互树
- iOS 之NSJSONReadingOptions说明【转】
- 穿越人海——化繁为简
- IM设计思考:XMPP安全机制
- 虚拟地址和物理地址的含义
- 高通平台环境搭建,编译,系统引导流程分析
- Java Socket编程