栈的简单基本操作(数据结构)
来源:互联网 发布:idea优化设置 编辑:程序博客网 时间:2024/05/21 19:31
#include<stdio.h>#include<stdlib.h>#define STACK_INIT_SIZE 100#define STACKINCREMENT 10#define ERROR 0#define OK 1#define OVERFLOW -1typedef char SElemType;typedef struct{SElemType *base;SElemType *top;int stacksize;}SqStack;int InitStack(SqStack *S){S->base=(SElemType*)malloc(STACK_INIT_SIZE*sizeof(SElemType));if(!S->base) exit(OVERFLOW);S->top=S->base;S->stacksize=STACK_INIT_SIZE;return OK;}int GetTop(SqStack *S){char e;if(S->top==S->base) return ERROR; e=*(S->top-1); printf("the top element is %c\n",e); return OK;}int Push(SqStack *S,SElemType e){if(S->top-S->base>=S->stacksize){ S->base=(SElemType *)realloc(S->base,(S->stacksize+STACKINCREMENT)*sizeof(SElemType)); if(!S->base) exit(OVERFLOW); S->top=S->base+S->stacksize; S->stacksize+=STACKINCREMENT;}*S->top++=e;return OK;}SElemType Pop(SqStack *S){SElemType e;if(S->top==S->base) printf("ERROR!!!");e=*--S->top;return e;}void main(){SqStack S;char ch[5];int i;SElemType e;if(InitStack(&S)==1) printf("creat stack succeed!\n");else printf("creat stack failed!\n");for(i=0;i<5;i++){ printf("input the %d element\n",i); scanf("%c",&ch[i]); getchar();}for(i=0;i<5;i++)Push(&S,ch[i]);if(GetTop(&S)==1) printf("get stack top succeed!\n");else printf("get stack top failed!\n");e=Pop(&S);printf("the pop element is %c\n",e);e=Pop(&S);printf("the top element is %c\n",e);}
栈的简单基本操作
- 栈的简单基本操作(数据结构)
- 【数据结构】 栈的基本操作
- 数据结构栈的基本操作
- 栈的基本操作-数据结构
- 【数据结构】栈的基本操作
- [数据结构]栈的基本操作
- 数据结构--栈的基本操作
- 数据结构--栈的基本操作
- 数据结构:栈的基本操作
- 数据结构-栈的基本操作
- 数据结构--栈的基本操作
- 【数据结构】二叉树的简单遍历及基本操作
- 数据结构(二)---基本的栈的操作
- 数据结构栈的基本的操作(C语言)
- 数据结构实验之栈八:栈的基本操作 简单方法
- 栈的基本操作(附带一个数据结构、C语言版)
- 数据结构---链栈的基本操作
- 数据结构--顺序栈的基本操作
- PreCreateWindow、PreSubclassWindow、SubclassWindow 解析
- HTML: scrollLeft,scrollWidth,clientWidth,offsetWidth 详解
- Mysql For Windows安装图解
- hdu 2577 dp
- jquery Dialog 对话框
- 栈的简单基本操作(数据结构)
- PathEffect类
- PE文件格式详解
- 转 Index Leaf Block contention Tuning
- 逝流年沧桑伤感日志_安静得,脑袋总在回忆从前
- Nginx中rewrite实现二级域名、三级域名、泛域名、路径的重写
- Linux双网卡绑定
- PowerDesigner 的mysql PDM 的COMMENT注释
- 学习《C和指针》