📄 check_st.c
字号:
#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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -