编辑代码

#include <stdio.h>
#include <stdlib.h>
#define datatype char
#define MAXSIZE 100
typedef struct 
{
    datatype data[MAXSIZE];
    int top;
}SEQSTACK;

void Init_Stack(SEQSTACK *s)
{
    s->top = -1;
}

int Stack_Empty (SEQSTACK *s)
{
    if(s->top==-1)
        return 1;
    else
        return 0;
}

void Push_Stack(SEQSTACK *s,datatype x)
{
    if(s->top==MAXSIZE-1)
        printf("Stack full\n");
    else
    {
        s->top++;
        s->data[s->top]=x;
    }
}

datatype Gettop_Stack(SEQSTACK *s)
{
    datatype x;
    if(Stack_Empty (s))
    {
        printf("Stack empty.\n");
        x=0;
    }
    else
        x=s->data[s->top];
    return x;
}

datatype Pop_Stack(SEQSTACK *s)
{
    datatype x;
    if(Stack_Empty (s))
    {
        printf("Stack empty\n");
        x=0;
    }
    else
    {
        x=s->data[s->top];
        s->top--;
    }    
    return x;
}

void Clear_Stack(SEQSTACK *s)
{
    s->top = -1;
}

int StackLength(SEQSTACK *s)
{
    return s->top+1;
}

int main()
{
    SEQSTACK stack,*s;
    s=&stack;
    Init_Stack(s);
    int x;
    printf("输入一个十进制的数:");
    scanf("%d",&x);
    while (x!=0)
    {
        Push_Stack(s,x%8);
        x=x/8;
    }
    while(!Stack_Empty(s))
    {
        printf("%4d",Gettop_Stack(s));
        Pop_Stack(s);
    }
}