#include#include#define MAXNUM 20struct stacktype{int stack[
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/10 11:26:19
#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
#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这个的错误
int e;
struct stacktype *s=NULL;
InitStack(s);
编译器说你的s没有初始化 你就把它赋值为NULL就可以了 像我这样
再问: 编译没错了,但是Linking... LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16 Debug/dafdfd.exe : fatal error LNK1120: 1 unresolved externals 执行 link.exe 时出错. dafdfd.exe - 1 error(s), 0 warning(s) 这里又错了
再答: 我没错啊 你是不是该了什么地方了呢 我的通过了啊
再问: 哦 我错了,不好意思 但是运行的时候错误了啊
再答: 其实你那样还是不对 不是声明一个S就好了 这样子改 就刚才我改的那个地方 struct stacktype *s=(struct stacktype *)malloc(sizeof(struct stacktype));改成这样子
再问: 但是你把数字输进去了,没答案就结束了啊
再答: 哎 你等问题真多啊·我在看看·· int StackEmpty(struct stacktype *s) {return(s->top==0); } 这个函数的问题 这么改吧 { if(s->top==0) { return 0; } else { return 1;} }
struct stacktype *s=NULL;
InitStack(s);
编译器说你的s没有初始化 你就把它赋值为NULL就可以了 像我这样
再问: 编译没错了,但是Linking... LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16 Debug/dafdfd.exe : fatal error LNK1120: 1 unresolved externals 执行 link.exe 时出错. dafdfd.exe - 1 error(s), 0 warning(s) 这里又错了
再答: 我没错啊 你是不是该了什么地方了呢 我的通过了啊
再问: 哦 我错了,不好意思 但是运行的时候错误了啊
再答: 其实你那样还是不对 不是声明一个S就好了 这样子改 就刚才我改的那个地方 struct stacktype *s=(struct stacktype *)malloc(sizeof(struct stacktype));改成这样子
再问: 但是你把数字输进去了,没答案就结束了啊
再答: 哎 你等问题真多啊·我在看看·· int StackEmpty(struct stacktype *s) {return(s->top==0); } 这个函数的问题 这么改吧 { if(s->top==0) { return 0; } else { return 1;} }
#include#include#define MAXNUM 20struct stacktype{int stack[
#include#include#include#define LEN sizeof(struct LinkList)s
进制转换#include"stdio.h"#define Max 50typedef struct{ int elem[
C语言 中&和 请参照这个程序#include#define NULL 0struct student{int num;
#include #include #include #include #include /* define
#include main() { struct node{int n;struct node *nest;} *p;
#include #include #define N 20main( ){ int a[N]={7,10,12,0,3
#include #include #define MAXLINE 1000int getline(char *line
英语翻译#include #include #include #include #define WIN_CONSOLE
#include #define M 20; void main() { int i,j,k,p,t,n=0; int
#include struct student { long num; char name[10]; int age;
#include#include#include#includeusing namespace std;#define