解题思路:栈的结构思想 后进先出的原则
注意事项:
参考代码:
#include<stdio.h>
#include<stdlib.h>
#define maxsize 100
#define stype int
typedef struct{
stype *base;
stype *top;
int size;}data; //用结构体构造一个栈的数据类型
int initstack(data *s)
{
s->base=(stype *)malloc(sizeof(stype)*maxsize);
if(!s->base)
{
exit(0);
return 0;
}
else
{
s->top=s->base;
s->size=maxsize;
return 1;
}
}
int getstack(data *s,stype *x)
{
if(s->base==s->top)
{
return 0;
}
else
{
*x=*(s->top-1);
return 1;
}
}
int pop(data *s,stype *x)
{
if(s->base==s->top)
{
return 0;
}
else
{
*x=*--s->top;
return 1;
}
}
int push(data *s,stype x)
{
if(s->top-s->base==maxsize)
return 0;
else
{
*s->top++=x;
return 1;
}
}
int main()
{
int n,m,x;
data *s;
s=(data *)malloc(sizeof(data));
initstack(s);
while(scanf("%d",&n)!=EOF)
{
m=n;
while(m)
{
push(s,m%8);
m=m/8;
}
while(s->base!=s->top)
{
pop(s,&x);
printf("%d",x);
}
putchar('\n');
}
return 0;
}
0.0分
0 人评分