模板类 栈
来源:互联网 发布:linux开机自启动命令 编辑:程序博客网 时间:2024/05/16 06:34
参考:《图解数据结构》,胡昭民著/* 模板类 实现栈 */#include<iostream>using namespace std;template< class Type = int, int size = 5>class Stack{ private: Type st[size];//数组作为栈的存储空间 int top;//栈顶数据顶端索引 public: Stack() { top = -1; } void push(Type data); Type pop();};template< class Type, int size >void Stack< Type, size>::push(Type data){ st[++top] = data;}template< class Type, int size >Type Stack< Type, size>::pop(){ return st[top--];}int main(){ Stack<> st_1; //Stack<char*,4> st_2; Stack<string> st_2; st_1.push(1); st_1.push(2); st_1.push(3); cout<<"stack_1 [1] = "<<st_1.pop()<<endl; cout<<"stack_1 [2] = "<<st_1.pop()<<endl; cout<<"stack_1 [3] = "<<st_1.pop()<<endl; cout<<endl; st_2.push("first"); st_2.push("second"); st_2.push("third"); cout<<"stack_2 [1] = "<<st_2.pop()<<endl; cout<<"stack_2 [2] = "<<st_2.pop()<<endl; cout<<"stack_2 [3] = "<<st_2.pop()<<endl; cout<<endl; system("pause"); return 0;}
阅读全文
0 0
- 类模板之栈
- 顺序栈类模板
- 栈模板类
- STL-栈类模板
- 栈类模板
- 类模板实现栈
- 模板类 栈
- 函数模板、类模板
- 模板 - 类模板
- 模板函数,模板类
- 模板的模板类
- 类模板(函数模板)
- 模板之---类模板
- C++模板:模板类
- 函数模板 类模板
- 函数模板、类模板
- 栈类模板的使用
- 栈的类模板实现
- sourceInsight4 破解笔记(完美破解)
- POJ 1006 Biorhythms 中国剩余定理
- 血管的三维重建
- 使用Gogs配置Git服务器(非源码)
- java:利用fastjson判断一个类型(java.lang.reflect.Type)是否是一个javabean
- 模板类 栈
- JS总结——数据类型
- asp.net查询数据显示等待中提示效果
- Linux 常用命令使用英文全称
- opensuse42.2vim安装YouCompleteMe
- GNS3环境qemu虚拟机linux通过cloud节点loopback桥接上网
- POJ 1222 EXTENDED LIGHTS OUT 二进制高斯消元 (开关翻转问题)
- Android消息机制—— Handler实现原理深度解析
- servlet程序HTTP Status 500