关于c语言和数据结构的问题。用顺序栈,将十进制转化为二进制

#include"stdio.h"#include"stdlib.h"#include"malloc.h"#defineMaxSize50typedefintElemTy... #include"stdio.h"#include"stdlib.h"
#include"malloc.h"
#define MaxSize 50
typedef int ElemType
typedef struct
{
ElemType data[MaxSize];
int top;
} Stack;

void InitStack(Stack *S) { S->top=-1;
}

int Push(Stack *S,ElemType x)
{ if(S->top==MaxSize-1){
printf("\n Stack is full!");
return 0; }
S->top++;
S->data[S->top]=x;
return 1;
}

int Pop(Stack *S,ElemType *x) { if(Empty(S)){
printf("\n Stack is free!");
return 0;
}
*x=S->data[S->top];
S->top--;
return 1;
}

int Empty(Stack *S)
{
return (S->top==0);
}

void conversion(int N)
{
int e;
Stack *S;

InitStack(S); while(N){
Push(S,N%2);
N=N/2;
}
while(!Empty(S)){
Pop(S,e);
printf("%d ",e)
}
}

void main(){
int n;
printf("请输入待转换的值n:\n");
scanf("%d",&n);
conversion(n);
}

vc++ 6.0 报错
G:\数据结构\实验\listwork2.cpp(7) : error C2143: syntax error : missing ';' before '<class-head>'
G:\数据结构\实验\listwork2.cpp(7) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.
展开
 我来答
shaoqi08110820
推荐于2017-11-25 · TA获得超过2508个赞
知道大有可为答主
回答量:1514
采纳率:100%
帮助的人:1766万
展开全部
//已改正,自己对照一下
#include"stdio.h"
#include"stdlib.h"
#include"malloc.h"
#define MaxSize 50
typedef int ElemType;
typedef struct
{
ElemType data[MaxSize];
int top;
} Stack;

void InitStack(Stack *S) { S->top=-1;
}

int Push(Stack *S,ElemType x){ if(S->top==MaxSize-1){
printf("\n Stack is full!");
return 0; }
S->top++;
S->data[S->top]=x;
return 1;
}
int Empty(Stack *S)
{
return (S->top==-1);
}
int Pop(Stack *S,ElemType *x)
{ if(Empty(S)){
printf("\n Stack is free!");
return 0;
}
*x=S->data[S->top];
S->top--;
return 1;
}

void conversion(int N){
int e;
Stack *S=(Stack*)malloc(sizeof(Stack));

InitStack(S); while(N){
Push(S,N%2);
N=N/2;
}
while(!Empty(S)){
Pop(S,&e);
printf("%d ",e);
}
}

void main(){ int n;
printf("请输入待转换的值n:\n");
scanf("%d",&n);
conversion(n);
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式