国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Stack

2019-11-08 18:40:36
字體:
來源:轉載
供稿:網友

簡單版 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;}*/


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 蕉岭县| 灵山县| 漠河县| 东乌珠穆沁旗| 微山县| 右玉县| 贵港市| 剑川县| 汉沽区| 姜堰市| 浮梁县| 建始县| 栾川县| 卢氏县| 河西区| 岳池县| 东山县| 苏尼特左旗| 忻城县| 乌什县| 安溪县| 江川县| 古蔺县| 抚宁县| 合阳县| 鹤岗市| 肥城市| 卢氏县| 黄冈市| 永城市| 丹阳市| 社会| 湟源县| 竹北市| 天门市| 都安| 嘉兴市| 巫溪县| 山阳县| 峨眉山市| 本溪市|