帮小弟我找下异常,数据结构C语言版实现十进制转换为八进制
帮我找下错误,数据结构C语言版实现十进制转换为八进制
[b]#include <Stdio.h>
#define Stack_Size 50
#define FALSE 0
#define TURE 1
typedef int ElementType;
typedef Struct Stack
{
StackElementType elem[Stack_Size];
int top;
}SeqStack;
void InitStack(SeqStack &S)
{
S->top==-1;
}
int PuSh(SeqStack &S,ElementType e)
{
if(S->top=Stack_Size-1) return(FALSE);
S->top++;
S->elem[S->top]=N;
return(TURE);
}
int Pop(SeqStack &S,ElementType *e)
{
/*if(S->top==-1) return(FALSE);
else
{
*e=S->elem[S->top];
printf("%d",*e);
S->top--;
return(TURE);*/
while(S->top!==-1)
{
*e=S->elem[S->top];
printf("%d",*e);
S->top--;
}
}
}
void main()
{
SeqStack S;
int e,N;
InitStack(S);
Scanf("%d",&N);
printf("请输入一个十进制数:");
while(N!=0)
{
PuSh(S,N%8);
N=N/8;
}
while(S->top!==-1)
{
Pop(S,e);
printf("%d",e);
}
}
void main()
{
SeqStack S;
int e,N;
InitStack(S);
Scanf("%d",&N);
printf("请输入一个十进制数:");
while(N!=0)
{
PuSh(S,N%8);
N=N/8;
}
while(S->top!==-1)
{
Pop(S,e);
printf("%d",e);
}
}
SeqStack S;
int e,N;
InitStack(S);
Scanf("%d",&N);
printf("请输入一个十进制数:");
while(N!=0)
{
PuSh(S,N%8);
N=N/8;
}
while(S->top!==-1)
{
Pop(S,e);
printf("%d",e);
}
}[/b]
------解决方案--------------------
[b]#include <Stdio.h>
#define Stack_Size 50
#define FALSE 0
#define TURE 1
typedef int ElementType;
typedef Struct Stack
{
StackElementType elem[Stack_Size];
int top;
}SeqStack;
void InitStack(SeqStack &S)
{
S->top==-1;
}
int PuSh(SeqStack &S,ElementType e)
{
if(S->top=Stack_Size-1) return(FALSE);
S->top++;
S->elem[S->top]=N;
return(TURE);
}
int Pop(SeqStack &S,ElementType *e)
{
/*if(S->top==-1) return(FALSE);
else
{
*e=S->elem[S->top];
printf("%d",*e);
S->top--;
return(TURE);*/
while(S->top!==-1)
{
*e=S->elem[S->top];
printf("%d",*e);
S->top--;
}
}
}
void main()
{
SeqStack S;
int e,N;
InitStack(S);
Scanf("%d",&N);
printf("请输入一个十进制数:");
while(N!=0)
{
PuSh(S,N%8);
N=N/8;
}
while(S->top!==-1)
{
Pop(S,e);
printf("%d",e);
}
}
void main()
{
SeqStack S;
int e,N;
InitStack(S);
Scanf("%d",&N);
printf("请输入一个十进制数:");
while(N!=0)
{
PuSh(S,N%8);
N=N/8;
}
while(S->top!==-1)
{
Pop(S,e);
printf("%d",e);
}
}
SeqStack S;
int e,N;
InitStack(S);
Scanf("%d",&N);
printf("请输入一个十进制数:");
while(N!=0)
{
PuSh(S,N%8);
N=N/8;
}
while(S->top!==-1)
{
Pop(S,e);
printf("%d",e);
}
}[/b]
------解决方案--------------------
- C/C++ code
#include <stdio.h> #define Stack_Size 50 #define FALSE 0 #define TURE 1 typedef int ElementType; typedef struct Stack { ElementType elem[Stack_Size]; int top; }SeqStack; void InitStack(SeqStack &S) { S.top=-1; } int PuSh(SeqStack &S,ElementType e) { if(S.top == Stack_Size-1) return(FALSE); S.top++; S.elem[S.top] = e; return(TURE); } int Pop(SeqStack &S,ElementType &e) { if(S.top==-1) return(FALSE); else { e=S.elem[S.top]; S.top--; return(TURE); } } void main() { SeqStack S; int e,N; InitStack(S); printf("请输入一个十进制数:"); scanf("%d",&N); while(N!=0) { PuSh(S,N%8); N=N/8; } while(S.top !=-1) { Pop(S,e); printf("%d",e); } }