本人菜鸟,还请诸位大佬多多指点!!!
//没有考虑空栈的情况,为10进制转换为8进制;
#include <stdio.h>
#include <stdlib.h>
#define max 10
struct node
{
int *base;
int *top;
};
void Initstack(struct node *s)
{
s->base=(int )malloc(maxsizeof(int));
s->top=s->base;
}
void push(struct node *p,int e)
{
*(p->top)=e;
p->top++;
}
void pop(struct node *p)
{
p->top=p->top-1;
}
void conversion(struct node s,int n)
{
Initstack(s);
while(n!=0)
{
push(s,n%8);
n=n/8;
}
while(s->top!=s->base)
{
pop(s);
printf("%d ",(s->top));
}
}
int main()
{
struct node l;
int n;
scanf("%d",&n);
conversion(&l,n);
return 0;
}