check_st.c
来自「C语言数据结构课设作品 很经典 Don t Lose!」· C语言 代码 · 共 62 行
C
62 行
#include<stdio.h>
//#include<string.h>
#include<stdlib.h>
#define OK 1
#define TRUE 1
#define FALSE 0
#define ERROR 0
#define OVERFLOW -2
#define STACK_INIF_SIZE 40
#define STACKINCREMENT 10
typedef int status;
typedef struct sqstack{
int *base;
int *top;
int stacksize;
}sqstack;
status *initstack(sqstack *s){
(s)->base = (int*)malloc(STACK_INIF_SIZE*sizeof(int));
if((s)->base==NULL) exit(OVERFLOW);
(s)->top=(s)->base;
(s)->stacksize = STACK_INIF_SIZE;
printf("initstack is finished!\n");
return OK;
}
int gettop(sqstack *s){
int e;
if(s->top==s->base){
printf("NULL1\n");
return NULL;
}
e=*(s->top-1);
printf("gettop %d is OK!\n",e);
return e;
}
status push(sqstack *s,int e){
if(s->top-s->base>=s->stacksize){
s->base=(int*)realloc(s->base,(s->stacksize+STACKINCREMENT)*sizeof(int));
if(!s->base) exit(OVERFLOW);
s->stacksize+= STACKINCREMENT;
}
*(s->top++)=e;
printf("push %d is OK\n",e);
return OK;
}
status pop(sqstack *s,int *e){
if(s->top==s->base){
printf("NULL2\n");
return ERROR;
}
*e=*(--(s->top));
printf("pop %d is OK!/n",*e);
return OK;
}
void main(){
int a=3,b,e;
sqstack *s;
initstack(s);
push(s,a);
b=gettop(s);
pop(s,&e);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?