关于栈的反向输出整数序列。

输入一个整数序列(非负整数,只含 正整数 和 0 )。序列以-1 结束。要求反向输出这个正整数序列。 要求定义一个栈来实现这个程序的功能。 输入 一个整数序列,每个数之间以空格隔开,非负整数,只含 正整数 和 0 。-1 表示输入结束。 输出 反向输出输入文件中的整数序列。 提示: 在C语言程序中使用 bool 类型,必须包含头文件 stdbool.h

函数接口定义:
栈的定义如下:

typedef int ElemType;

typedef struct
{
ElemType *base; //指向栈的元素存储空间
int top; // 栈顶
int capacity; // 当前已分配空间,以元素为单位
}Stack;

写出 createStack,push, pop,top,empty,destroy函数的定义。函数声明如下:

Stack* createStack(void); //初始化一个空栈。空栈拥有16个元素的空间,栈顶值为 -1

void push(Stack *pStack, ElemType x);//把 x 入栈

ElemType top(Stack *pStack);//返回当前栈顶元素的值

void pop(Stack *pStack); //当前栈顶元素出栈

bool empty(Stack *pStack);//如果栈空,则返回 true,否则返回 false

void destroy(Stack *pStack);//清空分配给栈的存储空间

裁判测试程序样例:
#include
#include
#include

typedef int ElemType;

typedef struct
{
ElemType *base; //指向栈的元素存储空间
int top; // 栈顶
int capacity; // 当前已分配空间,以元素为单位
}Stack;

Stack* createStack();
void push(Stack* pStack, ElemType x);
void pop(Stack* pStack);
ElemType top(Stack* pStack);
bool empty(Stack* pStack);
void destory(Stack* pStack);

int main(void)
{
Stack* pStack;
pStack = createStack();
int x;
scanf("%d", &x);
while (x != -1)
{
push(pStack, x);
scanf("%d", &x);
}
while (!empty(pStack))
{
x = top(pStack);
printf("%d ", x);
pop(pStack);
}
destory(pStack);
return 0;
}

/* 请在这里填写答案 */

输入样例:
在这里给出一组输入。例如:

3 127 64 1991 -1

输出样例:
在这里给出相应的输出。例如:

1991 64 127 3

问题解决的话,请点采纳

#include <stdio.h>
#include <stdlib.h>

typedef int ElemType;
#define N 100


typedef struct
{
    ElemType *base; //指向栈的元素存储空间
    int top; // 栈顶
    int capacity; // 当前已分配空间,以元素为单位
}Stack;

Stack* createStack();
void push(Stack* pStack, ElemType x);
void pop(Stack* pStack);
ElemType top(Stack* pStack);
bool empty(Stack* pStack);
void destory(Stack* pStack);

Stack* createStack(void)
{
    Stack * s = (Stack *)malloc(sizeof(Stack));
    s->capacity = N;
    s->top = 0;
    s->base = (ElemType *)malloc(sizeof(ElemType) * s->capacity);
    return s;
}

void push(Stack *pStack, ElemType x)
{
    pStack->base[pStack->top++] = x;
}
ElemType top(Stack *pStack)
{
    return pStack->base[pStack->top - 1];
}
void pop(Stack *pStack)
{
    pStack->top--;
}
bool empty(Stack *pStack)
{
    return pStack->top == 0;
}
void destory(Stack *pStack)
{
    free(pStack->base);
}

int main(void)
{
    Stack* pStack;
    pStack = createStack();
    int x;
    scanf("%d", &x);
    while (x != -1)
    {
        push(pStack, x);
        scanf("%d", &x);
    }
    while (!empty(pStack))
    {
        x = top(pStack);
        printf("%d ", x);
        pop(pStack);
    }
    destory(pStack);
    return 0;
}