解题思路:栈的结构思想 后进先出的原则
注意事项:
参考代码:
#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 人评分
弟弟的作业 (C++代码)浏览:1304 |
九宫重排 (C++代码)浏览:1335 |
A+B for Input-Output Practice (VII) (C++代码)浏览:615 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:543 |
【绝对值排序】 (C语言代码)浏览:821 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:633 |
Hello, world! (C语言代码)浏览:714 |
1054题解浏览:467 |
Quadratic Equation (C语言代码)浏览:988 |
前10名 (C语言代码)浏览:727 |