程序中一个奇怪的问题
#include <stdio.h>#include <stdlib.h>
#define stackinitsize 100
#define stackincrement 10
#define overflow 0
#define ok 1
#define error 0
typedef struct{
int *base;
int *top;
int stacksize;
}*sqstack;
int initstack(sqstack &s) //构造一个空栈
{
s->base=(int*)malloc(stackinitsize*sizeof(int));
if(!s->base) exit(overflow);
s->top=s->base;
s->stacksize=stackinitsize;
return 0;
}
int push(sqstack &s,int e) //插入元素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->top=s->base+s->stacksize;
s->stacksize+=stackincrement;
}
*s->top++ =e;
return ok;
}
int pop(sqstack &s,int &e) //删除栈顶元素
{
if(s->top==s->base)
return error;
e=*--s->top;
return ok;
}
int gettop(sqstack s, int &e) //返回栈顶元素
{
if(s->top==s->base)
return error;
e=*(s->top-1);
return ok;
}
void main()
{
int e;
int initstack(sqstack &s);
printf("请输入需要压入栈的数:");
scanf("%d",e);
int push(sqstack s, e);
int gettop(sqstack s, e);
}
----------------解决方案--------------------------------------------------------
好呀
希望各位同仁帮个忙,谢谢哥们了。 ----------------解决方案--------------------------------------------------------
到底什么问题?
你贴个代码就叫人回答问题拉? ----------------解决方案--------------------------------------------------------