c 语言数据结构栈的题目有点错误请高手调试
typedef int SElemType;typedef int Status;
typedef struct{
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
#define OK 1
#define OVERFLOW -1
#define ERROR 0
#include <malloc.h>
#include <stdio.h>
//InitStack/*构造一个空的栈s*/
Status InitStack(SqStack &s)
{ s.base=(SElemType *)malloc
(STACK_INIT_SIZE * sizeof(SElemType));
if(!s.base) return(OVERFLOW);
s.top=s.base;
s.stacksize=STACK_INIT_SIZE;
return OK;
} /*InitStack*/
Status Push(SqStack &s,SElemType e)
{ SElemType * 1_temp;
if (s.top - s.base >=s.stacksize)
/*栈满追加存储空间*/
{1_temp=(SElemType*)realloc
(s.base,(s.stacksize+STACKINCREMENT)
*sizeof(SElemType));
if(!1_temp) return(OVERFLOW);
s.base=1_temp;
s.top=s.base+s.stacksize;
s.stacksize += STACKINCREMENT;
}
*(s.top++)=e; return OK;
} /* push */
Status Pop(SqStack &s,SElemType &e)
{ if (s.top==s.base)return ERROR;
e=*(--s.top);
return OK;
} /* POP */
int StackEmpty(SqStack s)
{
if(s.base == s.top) return 1;
else return 0;
}
void conversion(void)
{ SqStack s;
int N,b;
SElemType e;
InitStack(s);
scanf("%d%d",&N,&b);
while(b>1 && N>0){
Push(s,N%b);
N=N/b;
}
while(!StackEmpty(s)){
Pop(s,e);
printf("%d",e);
}
} /* conversion */
void main()
{
conversion();
}