#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
//顺序栈//栈储存数据的数目根据实际情况而定,这里假定为50
#define maxSize 50//栈储存数据的类型根据实际情况而定,这里假定为int
typedef int elemType;typedef struct
{
elemType data[maxSize];
//用于栈顶指针
int top;
} stack;void createStack(stack *s)
{
//结构体里面的变量不能初始化
s -> top = -1;
}//进栈
int push(stack *s,elemType e)
{
//满栈
if(s -> top == maxSize - 1)
{
return 0;
}
else
{
s -> top++;
s -> data[s -> top] = e;
return 1;
}
}//出栈
int pop(stack *s, elemType *e)
{
//空栈
if(s -> top == -1)
{
return 0;
}
else
{
//将要删除的栈顶元素赋值给e
*e = s -> data[s -> top];
s -> top--;
return 1;
}}
void readStack(stack *s)
{
elemType n;
stack *temp = s;
while(temp -> top != -1)
{
if(pop(temp,&n))printf("%d",n);
}
printf("\n");
}int main()
{
elemType e,i;
stack s;
printf("输入转换数据及转换进制\n");
scanf("%d %d",&e,&i);
getchar();createStack(&s);
while(e !=0 )
{
elemType n;
n = e % i;
push(&s,n);
e = e / i;
}
readStack(&s);return 0;
}