数据结构_3:栈:C++
来源:互联网 发布:阿里云系统应用市场 编辑:程序博客网 时间:2024/06/15 20:32
自定义的stack
- 数据结构
template<class T>class Stack {// LIFO objects public: Stack(int MaxStackSize = 10); ~Stack() {delete [] stack;} bool IsEmpty() const {return top == -1;} bool IsFull() const {return top == MaxTop;} T Top() const; Stack<T>& Add(const T& x); Stack<T>& Delete(T& x); private: int top; // current top of stack int MaxTop; // max value for top T *stack; // element array};
- 类方法
template<class T>Stack<T>::Stack(int MaxStackSize){// Stack constructor. MaxTop = MaxStackSize - 1; stack = new T[MaxStackSize]; top = -1;}template<class T>T Stack<T>::Top() const{// Return top element. if (IsEmpty()) throw OutOfBounds(); // Top fails return stack[top];}template<class T>Stack<T>& Stack<T>::Add(const T& x){// Add x to stack. if (IsFull()) throw NoMem(); // add fails stack[++top] = x; return *this;}template<class T>Stack<T>& Stack<T>::Delete(T& x){// Delete top element and put in x. if (IsEmpty()) throw OutOfBounds(); // delete fails x = stack[top--]; return *this;}
0 0
- 数据结构_3:栈:C语言
- 数据结构_3:栈:C++
- 数据结构_3:栈:STL
- 初学C#_3
- Dissection C Chapter 1_3
- 重学c语言_3
- C/C++笔试题_3
- c++_3: 继承和组合
- C语言循环结构_3
- C++_3种预处理功能
- c/c++笔试面试题_3
- 【足迹C++primer】32、定制操作_3
- const相关用法(Effective C++_3)
- 《21天学通C++》_3 2016.5.24
- 数据结构与算法学习笔记02_3(线性表)
- [数据结构_3]图的邻接矩阵与邻接表
- C数据结构 栈
- <C/C++数据结构> 栈
- Sicily 1198. Substring
- 做一个有思想的程序猿
- 正则表达式实现简单的邮箱格式验证
- ubantu下安装zlib的方法
- 离散数学3____一些重要的重言蕴涵式__推理定律
- 数据结构_3:栈:C++
- python爬虫之神器正则表达式
- php 与mysql 连接
- 谓词函数
- android view第一次执行动画无效
- mysql权限覆盖
- 深入理解 Javascript 面向对象编程
- 启动mysql 报错,,Starting MySQL.Manager of pid-file quit without updating fi[失败] (2011-10-28 12:30:56)转载▼
- 宽字符与窄字符的转换