编辑代码

#include <stdio.h>
#define datatype char
#define MAXSIZE 100
typedef struct
{
    datatype data[MAXSIZE];
    int top;
}SEQSTACK   ;
//定义指针
SEQSTACK *s;
//初始化空栈
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=NULL;
    }
    else
    x=s->data[s->top];
    return x;
}
//出栈
datatype Pop_Stack(SEQSTACK *s)
{
    datatype x;
    if(Stack_Empty (s))
    {
        printf("Stack empty\n");
        x=NULL;
    }
    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;
}

main()
{
    SEQSTACK Stack,*s;
    char ch;
    s=&stack;
    Init_Stack(s);
    scanf("%c",&ch);
    while(ch!='\n')
    {
        Push_Stack(s,ch);
        scanf("%c",&ch);
    }
    printf("%d\n",StackLength(s)    );
    while(!Stack_Empty(s))
    {
        ch=Gettop_Stack(s);
        printf("%c",ch);
        Pop_Stack(s);
    }
}