栈_数列反转
来源:互联网 发布:淘宝备注在哪 编辑:程序博客网 时间:2024/06/05 23:50
栈_数列反转
#include<iostream>#include<string>#include<cassert>using namespace std;template<class Type> class Stack {private: Type *urls; int max_size, top_index;public: Stack(int length_input) { urls = new Type[length_input]; max_size = length_input; top_index = -1; } ~Stack() { delete[] urls; } bool push(const Type &element) { if (top_index >= max_size - 1) { return false; } top_index++; urls[top_index] = element; return true; } bool pop() { if (top_index < 0) { return false; } top_index--; return true; } Type top() { assert(top_index >= 0); return urls[top_index]; } bool empty(){ if( top_index<0){ return true; } else{ return false; } }};int main() { //n表示输入元素个数 int n,num; cin>>n; Stack<int> stack(n); //定义一个int类型的栈 for(int i=1;i<=n;i++){ cin>>num; stack.push(num); } while(!stack.empty()){ cout<<stack.top()<<" "; stack.pop(); } return 0;}
0 0
- 栈_数列反转
- Lisp---数列反转
- 分治_数列最大值
- 题目_数列有序
- Java_数组操作_反转
- 算法_二叉树反转
- 16_反转链表
- [wxWidgets]_[初级]_[反转wxString字符串]
- 1030_完美数列(25)
- 201509-1_数列分段
- 类斯特灵数列_分盒子
- 洛谷 1181_数列分段_贪心
- 反转栈
- [VB.NET源码]37_反转字符串
- 指针_字符串反转(reverse_string)
- 数据结构_单链表的建立与反转
- Java_集合操作_反转集合
- 1025_反转链表 (25)
- 栈的基本操作
- 11G新特性 -- Expression Statistics
- 正则表达式的学习之提取字符串中用“|”分割开的单词
- windows下盘符路径
- leetcode #41 in cpp
- 栈_数列反转
- Watch Face Complications
- Leetcode no. 200
- Deferred Statistics Publishing
- javascript判断对象属性是否存在两种方法
- 安卓设置更改系统字体大小,影响App展示
- Maven的安装和配置
- Maven小试牛刀
- 布局 与 jQuery插件