本题要求实现顺序栈,写出Push 、Pop函数。函数接口定义:Status Push(SeqStack L, ElemType e);Status Pop(SeqStack L, ElemType &e);其中 L 和 e 都是用户传入的参数。 L 是带头结点的头指针; e 是数据元素。 其中SeqStack定义如下:typedef struct{ ElementType Data[MaxSize]; // 存储元素的数组 Position Top; //栈顶指针}SeqStack;待完善程序如下:#include <malloc.h>#include <stdio.h>#define MaxSize 100 /* 堆栈最大容量 */#define OK 1#define ERROR 0typedef int Status;typedef int ElemType;typedef int Position;typedef struct{ ElemType Data[MaxSize]; /* 存储元素的数组 */ Position top; /* 栈顶指针, 指示栈顶元素之后的位置 */}SeqStack;Status StackEmpty(SeqStack s);Status Push(SeqStack L, ElemType e);Status Pop(SeqStack L, ElemType &e);int main(){ SeqStack s; ElemType x; s.top = 0; //初始化链栈 Push(s, 1); Push(s, 2); Push(s, 3); while(!StackEmpty(s)) { Pop(s, x); printf(" %d", x); } return 0;}Status StackEmpty(SeqStack s) //判断栈s是否为空{ return s.top == 0;}/* 请在这里填写答案 */
本题要求实现顺序栈,写出Push 、Pop函数。函数接口定义:Status Push(SeqStack L, ElemType e);Status Pop(SeqStack L, ElemType &e);其中 L 和 e 都是用户传入的参数。 L 是带头结点的头指针; e 是数据元素。 其中SeqStack定义如下:typedef struct{ ElementType Data[MaxSize]; // 存储元素的数组 Position Top; //栈顶指针}SeqStack;待完善程序如下:#include