#define _CRT_SECURE_NO_DEPRECATE//解决CRT函数安全增强的问题
#include
#include
#include
#define StackSize 100
typedef int ElemType; //采用这种方式更方便修改代码
typedef struct{ //定义顺序栈的数据类型
ElemType data[StackSize];
int top;
}Sq_Stack;
int Init_Push_Stack(Sq_Stack* &Q) //构造一个空的顺序栈并初始化
{
int i;
int n;
Q = (Sq_Stack*)malloc(sizeof(Sq_Stack));
if (!Q->data)
printf('Overflow');
Q->top = -1;
printf('请输入入栈元素的个数:');
scanf('%d', &n);
if (n == 0)
return 0;
if (n > StackSize)
printf('OverFlow!');
for (i = 0; i < n; i++)
{
printf('请输入入栈的元素:');
Q->top++;
scanf('%d', &Q->data[i]);
}
printf('顺序栈的长度为:%d', Q->top + 1);
return 0;
}
void Pop_Stack(Sq_Stack* &Q) //顺序栈的出栈
{
int n;
int i;
if (Q->top == -1)
printf('ERROR');
printf('请输入出栈元素的个数:');
scanf('%d', &n);
if (Q->top + 1 <
#include
#include
#include
#define StackSize 100
typedef int ElemType;
typedef struct{
ElemType data[StackSize];
int top;
}Sq_Stack;
int Init_Push_Stack(Sq_Stack* &Q)
{
int i;
int n;
Q = (Sq_Stack*)malloc(sizeof(Sq_Stack));
if (!Q->data)
printf('Overflow');
Q->top = -1;
printf('请输入入栈元素的个数:');
scanf('%d', &n);
if (n == 0)
return 0;
if (n > StackSize)
printf('OverFlow!');
for (i = 0; i < n; i++)
{
printf('请输入入栈的元素:');
Q->top++;
scanf('%d', &Q->data[i]);
}
printf('顺序栈的长度为:%d', Q->top + 1);
return 0;
}
void Pop_Stack(Sq_Stack* &Q)
{
int n;
int i;
if (Q->top == -1)
printf('ERROR');
printf('请输入出栈元素的个数:');
scanf('%d', &n);
if (Q->top + 1 <
