算法导论 chapter 10.1 Page233 Stack push and pop
来源:互联网 发布:阿里云的黑洞模式 编辑:程序博客网 时间:2024/06/06 00:22
//***算法导论 chapter 10 Elementary Data Structures***/////Page 233 伪代码转换成代码//Stack push and pop#include <iostream>#define TRUE 1#define FALSE 0using namespace std;int stack_array[20]={0};//定义一个数组,当做桟来使用 int top=0; //top指示桟的顶端元素,0代表桟为空//判断桟是否为空,为空返回1,反之为0 int stack_empty(int top){if(top==0) return TRUE; else return FALSE;}//将新元素x压入桟中 int push(int *ptr, int x){top+=1;*(ptr+top)=x;return 0;}//将顶端的元素弹出桟,并返回弹出的元素 int pop(int *ptr){if(stack_empty(top)==1) cout<<"underflow"<<endl; else { top-=1; return *(ptr+top+1); } return 0;}//打印桟void print_stack(int *ptr){if(stack_empty(top)==1) cout<<"The stack is empty."<<endl; else { for(int i=1;i<=top;++i) { cout<<*(ptr+i)<<" "; } cout<<"Top = "<<top; cout<<endl; }} int main(){ push(stack_array,15); push(stack_array,6); push(stack_array,2); push(stack_array,9); print_stack(stack_array); pop(stack_array); print_stack(stack_array); return 0;}
0 0
- 算法导论 chapter 10.1 Page233 Stack push and pop
- stack manipulation push and pop
- .set push and .set pop
- 算法导论示例-Stack
- No. 21 - Push and Pop Sequences ofStacks
- Object-C系列-<push and pop>
- ARM 指令集 之 PUSH and POP
- 算法导论(中文版)--chapter 1
- 【15】Design a stack which has push pop min max
- PUSH/POP
- 用一个单链表L实现一个栈 要求PUSH和POP操作的时间仍为O(1) 算法导论10.2-2答案
- 《算法导论》— Chapter 6 堆排序
- 《算法导论》 — Chapter 7 快速排序
- 算法导论习题(python)Chapter One
- 《算法导论》 — Chapter 10 基本数据结构
- 《算法导论》— Chapter 11 散列表
- 《算法导论》— Chapter 15 动态规划
- 算法导论(C++实现) chapter 2
- 字符数组
- Java hascode()
- java 基本数据类型及自动类型提升
- 类模板详解
- 黑马程序员--浅复制与深复制
- 算法导论 chapter 10.1 Page233 Stack push and pop
- JQuery上传插件Uploadify使用详解
- google+登录API 续
- android apk裁剪定制
- poj 2478/3090 欧拉函数应用(Farey 序列/斜率判重)
- android自定义View(二)
- cocos2dx 3.0 触摸机制
- URAL 1903 Unidentified Ships(大数组合数打表取模)
- [leetcode] Merge Two Sorted Lists