#include <stdio.h>
#include <stdlib.h>
#define max_num 100000
typedef int ElemType;
typedef struct node
{
ElemType *bottom;
ElemType *top;
int stack_size;
}SqStack;
void *initialStack(SqStack *s)
{
s->bottom = (ElemType *)malloc(max_num*sizeof(ElemType));
if(!s->bottom)
exit(0);
s->top = s->bottom;
s->stack_size = max_num;
}
void *push(SqStack *s,int n,int m)
{
while(n){
s->top = n%m;//这里我一直弄不清楚,s->top不知道应该算是什么类型,但是被int赋值C的编译器居然可以过,我想应该用指针吧,但是又报错
n /= m;
s->top++;
}
}
void *pop(SqStack *s)
{
while(s->top>s->bottom){
s->top--;
printf("%d",s->top);
}
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
SqStack *s;
initialStack(s);
push(s,n,m);
pop(s);
return 0;
}
http://cart55free99.blog.163.com/blog/static/8535985120112694226288/
参考看看这个。。。
把
s->top = n%m;
修改成
*(s->top) = n%m;