数据结构作业,要求输入一个十进制的数,转换为二进制输出。本人新手,自己编的代码,为何不能输出结果?
本人新手,自己编的代码,但是为什么不能输出结果?求大牛指点!急急急!!感激不尽哈#include<stdio.h>
#include<stdlib.h>
typedef int Elemtype;
#define M 100
typedef struct
{
Elemtype data[M];
int top;
}sqstack;
void Initsqstack(sqstack *&s)
{
s=(sqstack *)malloc(sizeof(sqstack));
s->top=-1;
}
bool stackEmpty(sqstack *s)
{
return(s->top==-1);
}
bool push(sqstack *&s,Elemtype e)
{
if(s->top==M-1)
return false;
s->top++;
s->data[s->top]=e;
return true;
}
bool pop(sqstack *&s,Elemtype &e)
{
if(s->top==-1)
return false;
e=s->data[s->top];
s->top--;
return true;
}
int main()
{
Elemtype e,n;
sqstack *st;
scanf("%d",&n);
st=(sqstack *)malloc(sizeof(int));
if(st==NULL)
return 0;
Initsqstack(st);
while(e!=0)
{
push(st,e=n%2);
n=n/2;
}
while(e!=0)
{
pop(st,e=n%2);
n=n/2;
printf("%d",e);
}
}
free(st);
return true;
}