#include#include#define MAXNUM 20struct stacktype{int stack[MAXNUM];int top;};void InitStack(struct stacktype *s){s->top=-1;}int StackEmpty(struct stacktype *s){return(s->top==0);}int push(struct stacktype *s,int x){ if(s->top >= MAXNUM-1)return fals

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/03 01:17:41
#include#include#define MAXNUM 20struct stacktype{int stack[MAXNUM];int top;};void InitStack(struct stacktype *s){s->top=-1;}int StackEmpty(struct stacktype *s){return(s->top==0);}int push(struct stacktype *s,int x){ if(s->top >= MAXNUM-1)return fals

#include#include#define MAXNUM 20struct stacktype{int stack[MAXNUM];int top;};void InitStack(struct stacktype *s){s->top=-1;}int StackEmpty(struct stacktype *s){return(s->top==0);}int push(struct stacktype *s,int x){ if(s->top >= MAXNUM-1)return fals
#include
#include
#define MAXNUM 20
struct stacktype
{
int stack[MAXNUM];
int top;
};
void InitStack(struct stacktype *s)
{s->top=-1;
}
int StackEmpty(struct stacktype *s)
{return(s->top==0);
}
int push(struct stacktype *s,int x)
{ if(s->top >= MAXNUM-1)
return false;
else
s->top++;
s->stack[s->top]=x;
return true;
}
int pop(struct stacktype *s)
{ if(s->top top--;
return(s->stack[s->top+1]);
}
void dec_to_bin(int N,int B)
{
int e;
struct stacktype *s;
\x05InitStack(s); //初始化堆栈,算法定义见课本
\x05while(N){
\x05\x05push(s,N%B);
\x05\x05N=N/B;
\x05}
\x05while(StackEmpty(s)){ //堆栈判空,算法定义见课本
\x05\x05e=pop(s);
\x05\x05printf("%d",e);
\x05}
}
void main()
{int a;
scanf("%d",&a);
dec_to_bin(a,2);
}
运行没有错误但就是出现local variable 's' used without having been initialized这个的错误

#include#include#define MAXNUM 20struct stacktype{int stack[MAXNUM];int top;};void InitStack(struct stacktype *s){s->top=-1;}int StackEmpty(struct stacktype *s){return(s->top==0);}int push(struct stacktype *s,int x){ if(s->top >= MAXNUM-1)return fals
int e;
struct stacktype *s=NULL;
InitStack(s);
编译器说你的s没有初始化 你就把它赋值为NULL就可以了 像我这样