#include<stdio.h>
typedef struct{
int data[100];
int top;
}Stack;
void InitStack(Stack &S)
{
S.top=-1;
}
void Push (Stack &S,int x) //入栈
{
S.top++;
S.data[S.top]=x;
}
void Pop(Stack S) //出栈
{
int i;
for (i=S.top;i>=0;i--)
{
printf ("%d ",S.data[i]);
}
}
void Delete (Stack &S) //删除栈顶元素
{
S.data[S.top--]=NULL;
}
int main ()
{
Stack S;
InitStack(S);
int n,b;
int m,i;
while (scanf ("%d%d",&n,&b)!=EOF)
{
while (n!=0)
{
m=n%b;
Push (S,m);
n=n/b;
}
Pop(S);
printf ("\n");
while (S.top>=0)
Delete (S);
}
return 0;
}
栈的顺序存储实现进制转换
最新推荐文章于 2023-02-15 16:00:19 发布