栈的实现和基本操作
来源:互联网 发布:什么时候开放网络购彩 编辑:程序博客网 时间:2024/06/05 09:39
栈是一种常用的数据结构,可以帮助我们有效地保存临时数据.它遵循LIFO(Last In First Out)的原则.
它有push(),pop(),isEmpty(),isFull()几个常用操作.今天我们就试着用C++来创建一个栈,并用函数表达出这些功能.
#include<iostream>#include<cstdio>using namespace std;int Stack[1000],top=-1;bool isFull(){ if(top==999) { return true; } else { return false; }}bool isEmpty(){ if(top==-1) { return true; } else { return false; }}void push(int num){ if(!isFull()) { Stack[top+1]=num; top++; } else { printf("The stack is full.") }}int pop(){ if(!isEmpty) { int num=Stack[top]; top--; return num; } else { printf("The stack is empty.") }}int main(){ return 0;}
像这样我们就可以构建出一个以Stack[0]为底的栈,并且实现这四个基本操作.
阅读全文
0 0
- 栈和队列的基本操作实现
- 栈的实现和基本操作
- 顺序栈和链栈的基本操作实现
- 栈的基本操作和实现C++模板类
- 单链表的实现和基本操作
- 线性表的基本操作和实现
- 栈的实现及基本操作
- 用数组实现栈的基本操作
- 顺序栈的基本操作实现
- 顺序栈的基本操作实现
- 顺序栈的基本操作实现
- 链栈的基本操作实现
- 栈的基本操作实现-c/c++
- 栈的实现及基本操作
- C++实现链栈的基本操作
- 1044 顺序栈基本操作的实现
- 链式栈的基本操作与实现
- C语言实现栈的基本操作
- XZ_iOS之异步裁切绘制圆角图形
- 网页以FTP方式发布到Server的粗略过程
- 阿里云部署Java web的步骤
- Adaboost算法
- 1035. 插入与归并
- 栈的实现和基本操作
- cad转出高清图片的方法。分享
- String painter HDU
- 机器学习基石 7.4 Interpreting VC Dimension
- spring创建对象的几种方式
- tomcat 运行慢解决方案汇总
- 机器学习基础及框架
- Page Count
- 给Linux内核打patch