使用数组实现堆栈
2011-05-22 14:46
316 查看
#include <stdio.h> #include <stdlib.h> #define MAX 10 int stack[10]; int top=-1; void push(int number) { printf("push a number\n"); if(top>=9) { printf("the stack is full"); }else{ top++; stack[top]=number; } } int pop() { int temp; printf("pop a number\n"); if(top<0) { printf("the stack is empty"); return -1; }else{ temp=stack[top]; top--; printf("%d",temp); return temp; } } void show() { for(;top>=0;top--) { printf("%d\t",stack[top]); } } int main() { int select; int number; printf("(1)please input a stack data\n"); printf("(2)please output a stack data\n"); printf("(3)exit\n"); printf("please input one by input a number"); scanf("%d",&select); while(select!=3) { switch(select) { case 1:scanf("%d",&number);push(number);break; case 2:pop();break; default:exit;break; } printf("(1)please input a stack data\n"); printf("(2)please output a stack data\n"); printf("(3)exit"); printf("please input one by input a number\n"); scanf("%d",&select); } show(); return 0; }
相关文章推荐
- 使用JavaScript的数组实现数据结构中的队列与堆栈
- PHP中使用数组实现堆栈数据结构的代码
- 使用JavaScript的数组实现数据结构中的队列与堆栈
- 韩顺平_PHP程序员玩转算法公开课(第一季)07_使用数组实现堆栈_学习笔记_源代码图解_PPT文档整理
- 使用JavaScript的数组实现数据结构中的队列与堆栈
- 使用数组实现堆栈和队列
- Java数据结构之堆栈-使用数组实现堆栈
- 使用JavaScript的数组实现数据结构中的队列与堆栈
- 数据结构与算法-----堆栈-使用数组(顺序结构)实现
- PHP中使用数组实现堆栈数据结构的代码
- 使用JavaScript的数组实现数据结构中的队列与堆栈
- PHP使用数组实现堆栈和队列
- PHP中使用数组实现堆栈数据结构的代码
- 考研数据结构与算法之堆栈的使用(三)数组实现的堆栈
- 使用JavaScript的数组实现数据结构中的队列与堆栈
- 使用JavaScript的数组实现数据结构中的队列与堆栈
- 用一个数组实现两个堆栈,最大地使用数组的空间,只要有空间就能入栈成功
- JavaScript学习总结(二十一)——使用JavaScript的数组实现数据结构中的队列与堆栈
- j2se学习中的一些零碎知识点4之字符串,数组和异常(使用数组实现冒泡排序算法和选择排序以及二分法查
- 使用System.arraycopy()实现数组之间的复制