帮忙看下使用顺序栈,完成m进制到n进制的转换程序哪里错了?顺便帮写下程序的流程图!非常谢谢!!
#include <stdio.h>#include <stdlib.h>
#include <malloc.h>
#define MAX 100
typedef struct
{
int data[MAX];
int top;
}seqstack, *pseqstack;
pseqstack s;
//s = (pseqstack)malloc(sizeof(seqstack));
pseqstack init_seqstack()
{
pseqstack s;
s = (pseqstack)malloc(sizeof(seqstack));
if(s)
s ->top = -1;
return s;
}
int empty_seqstack(pseqstack s)
{
if(s ->top == -1)
return 1;
else
return 0;
}
int input_seqstack(pseqstack s,int x)
{
if(s ->top ==MAX - 1)
return 0;//栈满不能入栈
else
{
s ->top ++;
s ->data[s ->top] = x;
return 1;
}
}
int out_seqstack(pseqstack s)
{
int x;
if (empty_seqstack(s)) //栈空不能出栈
return 0;
else
{
x = s ->data[s ->top];
s ->top--;
printf("%d",x);
return 1;
}
}
int gettop_seqstack(pseqstack s)
{
int x;
if(empty_seqstack(s))
return 0;
else
{
x = s->data[s ->top];
return (1);
}
}
int change(int x)
{
int n;
pseqstack s;
s = (pseqstack)malloc(sizeof(seqstack));
s->top=-1; //初始化后要设top为-1
while(x != 0)
{
n = x % n;
input_seqstack(s,n);
x = x / n;
}
while(s->top>-1)
{
out_seqstack(s);//
}
putchar('\n');
return 1;
}
int main()
{
int n;
pseqstack s;
s = (pseqstack)malloc(sizeof(seqstack));
printf("输入要转化的进制整数:\n");
scanf("%d",&n);
//printf("选择你要转换成的进制数:\n");
change(n);
return 0;
}