#include<stdio.h>
#define OK 1
#define Maxsize 10
typedef int SElemtype;
typedef int Status;
typedef struct
{
SElemtype data[Maxsize];
SElemtype top;
}StackList;
StackList* S;
Status InitStack(StackList* S) //初始化栈
{
scanf_s("%d", &S->data[S->top]);
if (S->data[S->top])
{
S->top++;
InitStack(S);
}
else
{
S->top--;
}
}
Status Print(StackList* S) //出栈打印
{
int i;
for (int i = S->top; i >= 0; i--)
{
printf("%d ", S->data[i]);
}
}
Status Push(StackList* S, SElemtype* e) //插入操作
{
S->top++;
S->data[S->top] = *e;
}
int main()
{
SElemtype e;
S = (StackList*)malloc(sizeof(StackList));
S->top = 0;
InitStack(S);
Print(S);
printf("\n请输入插入元素:");
scanf_s("%d", &e);
Push(S, &e);
Print(S);
return 0;
}
栈—顺序结构
最新推荐文章于 2024-09-05 11:35:52 发布