Stack 的C++实现
来源:互联网 发布:软件测试名词解释 编辑:程序博客网 时间:2024/05/21 16:02
template<typename T>class Stack{public:Stack(int s = 10);~Stack();public:T top();void push(T t);T pop();bool empty();int size();private:int count;int capacity;T* array;};template<typename T>Stack<T>::Stack(int s){count = 0;capacity = s;array = new T[capacity];}template<typename T>Stack<T>::~Stack(){delete[] array;array = NULL;}template<typename T>T Stack<T>::top(){if (count <= 0){return NULL;}return array[count - 1];}template<typename T>void Stack<T>::push(T t){if (count >= capacity)return;array[count++] = t;}template<typename T>T Stack<T>::pop(){if (count <= 0){return NULL;}return array[--count];}template<typename T>bool Stack<T>::empty(){return count == 0 ? true : false;}template<typename T>int Stack<T>::size(){return count;}
阅读全文
0 0
- 纯C的Stack实现
- [C#]Stack类的实现
- C语言,简单栈的实现 Stack
- 动态栈Stack的C语言实现
- C++:栈(stack)的模板类实现
- 栈(Stack)的C语言实现
- Stack链表C实现
- c语言 ---- Stack实现
- C和C++实现Stack
- C语言实现stack模板
- C和C++实现Stack
- 栈(Stack) C 语言实现
- C语言Stack简单实现
- C.Interface.And.Implementations—stack的实现
- stack容器的实现
- stack的数组实现
- stack的简单实现
- Stack 的 java 实现
- mpeg-ts(二)
- 为Hexo加入浏览量的功能
- Java加盐加密
- 浅析 Angular $q promise 回调异步嵌套解决机制
- 通过互斥锁Mutex和条件变量Conditions实现动态平衡,模拟生活中卖包子的情景
- Stack 的C++实现
- 关于黏包
- Keepalived 工作原理及简要安装
- 红黑树(RB-tree)比AVL树的优势在哪?
- 绝对路径的写法
- session
- 像素和分辨率
- Java修饰符以及Kotlin修饰符对比
- Android 文件下载三种基本方式