一道数据结构题:#include #include #define STACK_INIT_SIZE 100#define STACKINCREMENT 10#define OK 1#define ERROR 0typedef struct{int *base;int *top;int stacksize;}SqStack;int InitStack(SqStack *S){S->base=(int *)malloc(STACK_INIT_SIZE*sizeof(i

来源:学生作业帮助网 编辑:作业帮 时间:2024/10/01 01:44:29
一道数据结构题:#include #include #define STACK_INIT_SIZE 100#define STACKINCREMENT 10#define OK 1#define ERROR 0typedef struct{int *base;int *top;int stacksize;}SqStack;int InitStack(SqStack *S){S->base=(int *)malloc(STACK_INIT_SIZE*sizeof(i
xU[O`+unzփK\BÈސ [[N##@^qh"gn\zں Kϡ﷦Lx嚵qd?hY_/n9۾b&s)LώLGBDW)?=̍N_AHG`1jM4D"ECt`8c(s`Ea`N:*,)XƞhE(517bO䰒.Vb[UQ7.׃tUm_9N!'ױ^aNZJ뜪p;UEr,TY!,{\.߃vxsF<5mjF) s (q!cdy=bS릱phDՃhpeC|7^Ё Apr4zkkZjx b$z00'P.hwvC,$`gC)R5ܵ>ΕPi,!¦t`Cro艧ؗ*á)A It{uYXr*h'aBȇJq9^RfjtSjqQs%E4Yi &*n(S*R KT1Ar($ 8$e.% iY$%AfNCr[qIl.υXV`)eY9F.2E$M -@p=?sjp~P?^{}>.š+:Kbo]xc67OR?~뎲(p6<:\iyB

一道数据结构题:#include #include #define STACK_INIT_SIZE 100#define STACKINCREMENT 10#define OK 1#define ERROR 0typedef struct{int *base;int *top;int stacksize;}SqStack;int InitStack(SqStack *S){S->base=(int *)malloc(STACK_INIT_SIZE*sizeof(i
一道数据结构题:
#include
#include
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
#define OK 1
#define ERROR 0
typedef struct{
int *base;
int *top;
int stacksize;
}SqStack;
int InitStack(SqStack *S)
{
S->base=(int *)malloc(STACK_INIT_SIZE*sizeof(int));
if(!S->base) return ERROR;
S->top=S->base;
S->stacksize=STACK_INIT_SIZE;
return OK;
}
int 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) return ERROR;
S->top=S->base+S->stacksize;
S->stacksize+=STACKINCREMENT;
}
*(S->top)=e;
S->top++;
return OK;
}
int Pop(SqStack *S,int *e)
{
if(S->top==S->base) return ERROR;
*e=*(S->top-1);
return OK;
}
int GetTop(SqStack S,int *e)
{
if(S.top==S.base) return ERROR;
S.top--;
*e=*(S.top);
return OK;
}
void main()
{
SqStack S;
int i,j,*p;
i=2,j=4;
InitStack(&S);
Push(&S,i);
Push(&S,j);
GetTop(S,p);
printf("%d",*p);
}
为什么运行有错
用VC++是这样的:

一道数据结构题:#include #include #define STACK_INIT_SIZE 100#define STACKINCREMENT 10#define OK 1#define ERROR 0typedef struct{int *base;int *top;int stacksize;}SqStack;int InitStack(SqStack *S){S->base=(int *)malloc(STACK_INIT_SIZE*sizeof(i
我试了一下,没有问题的,程序运行结果是4,就是栈顶元素的值
手上没有VC++,我是用GCC编译的