Stack
来源:互联网 发布:博雅软件2017 编辑:程序博客网 时间:2024/04/30 05:48
简单版 Stack
Stack.h
#pragma oncetemplate<class T>class stack {public: stack(); ~stack(); bool empty(); T pop(); bool push(const T);private: T* data; int top;};
Stack.cpp
#include"Stack.h"#include<iostream>const int N = 100;template<class T>stack<T>::stack():top(0),data(new T[N]){}template<class T>stack<T>::~stack() { delete[] data;}template<class T>bool stack<T>::empty() { if (top < 1) return true; else return false;}template<class T>bool stack<T>::push(const T elem) { if (top < N) { data[top] = elem; ++top; return true; } return false;}template<class T>T stack<T>::pop() { if (empty()) { std::cout << "underflow" << std::endl; return T(); } return data[--top];}// ***************************** text ******************************/*int main() { stack<int> text; std::cout << "empty?:" << text.empty() << std::endl; text.push(1); text.push(15); text.push(6); text.push(66); text.push(8); std::cout <<"empty?:"<< text.empty() << std::endl; std::cout << "pop:" << text.pop() << std::endl; std::cout << "pop:" << text.pop() << std::endl; std::cout << "pop:" << text.pop() << std::endl; std::cout << "pop:" << text.pop() << std::endl; std::cout << "pop:" << text.pop() << std::endl; std::cout << "empty?:" << text.empty() << std::endl;}*/
0 0
- stack
- stack
- stack
- stack
- Stack
- Stack
- Stack
- Stack
- stack
- Stack
- stack
- stack
- Stack
- stack
- Stack
- Stack
- stack
- stack.
- [LeetCode]Contains Duplicate III
- 提题来见(1)
- mysql中的共享锁与排他锁
- Linux关于bash的二三事(2)
- 【Get深一度】ASCII表ASCII表ASCII表ASCII表
- Stack
- SQL with(nolock)详解
- 网格生产的常用算法
- 函数特性
- PL/SQL 标签与GOTO语句
- react native事件机制(Eventdispather)
- C++ Dll 导出类
- DataGuard之DG 故障切换(switchover和failover)以及利用flashback 进行恢复
- eclipse xml 无提示解决