栈 数组
来源:互联网 发布:百度云盘mac版下载 编辑:程序博客网 时间:2024/05/24 04:29
#include <iostream>using namespace std;typedef int T;class Stack{T a[10];int num;//记录已经放入的元素个数 public:void push(const T& t){if (full())throw "stack overflow";a[num++] = t;}void pop(){if (empty())throw "empty stack";num--;}T top(){if (empty())throw "no top stack";return a[num-1];} bool empty() { return num == 0; } bool full() { return num == 10; }int size(){return num;} int capacity(){return 10;}void clear(){num = 0;}Stack():num(0){}};int main(){Stack s;s.push(1);s.push(2);s.push(3);/*for (int i=0; i<10; i++){s.push(i*5);}*/while(!s.empty()){cout << s.top() << ' ';s.pop();}cout << endl;/*for (int i=0; i<10; i++)s.push(i);cout << "full?" << s.full() << endl;s.push(100); //there is an exceptioncout << "cant see this" << endl;*/}
阅读全文
0 0
- 数组栈
- 栈 数组
- 堆上数组&栈上数组
- 栈-数组模拟栈
- 堆,栈,数组
- 栈的数组实现
- 用数组实现栈
- 栈学习---数组实现
- 栈学习---数组实现
- 静态数组实现栈
- 动态数组实现栈
- 栈---数组---迷宫求解
- 栈---数组实现
- 用数组模拟栈
- 静态数组实现栈
- 动态数组实现栈
- 栈(数组实现)
- 数组仿真栈
- 搭建Ubuntu基本环境
- 总有你值得一试的python开源项目
- 【HIbernate】(五)关联映射之多对一映射
- 融云利用自定义消息的方式发送自定义表情
- TCP那些事儿(3)
- 栈 数组
- Spring Boot日志文件的配置学习笔记
- 打印机
- ABAP CDS 替代对象(Replacement Objects)引起的数据错误
- OpenGL光源位置
- spingMVC+poi导出文件
- AvaudioRecorder 录音
- git 基础命令
- 类型转换