题目:
编写C应用程序,使用顺序存储结构实现栈上的各种操作:初始化,销毁,入栈,出栈,取栈顶元素,求栈的长度、“判空”,并对
#define _CRT_SECURE_NO_WARNINGS
#define MaxSize 10
#define Status int
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef int ElemType;
//定义栈
typedef struct {
ElemType data[MaxSize];
int top; //栈顶指针
}SeqStack;
//初始化栈
Status InitStack(SeqStack& s)
{
for (int i = 0; i < MaxSize; i++)
{
s.data[i] = 0;
}
s.top = 0;
return 0;
}
//判空
bool StackEmpty(SeqStack& s)
{
if (s.top == 0)
return true;
else
return false;
}
bool PushStack(SeqStack & s, ElemType x)
{
if (s.top == MaxSize - 1)
return false;
for (int i = 0; i < x; i++)
{
scanf("%d", &s.data[i]);
s.top++;
}
return true;
}
//栈顶增加元素,入栈
bool Push(SeqStack& s, ElemType e)
{
if (s.top &