//栈的顺序存储实现
#include<stdio.h>
#define ElementType int
#define MaxSize 100
#define ERROR 0;
typedef struct SNode* Stack;
struct SNode {
ElementType Data[MaxSize];
int Top;
};
//入栈
void Push(Stack PtrS, ElementType item)
{
if (PtrS->Top == MaxSize - 1)
{
printf("堆栈满");
return;
}
else
{
PtrS->Data[++(PtrS->Top)] = item;
}
}
//出栈
ElementType Top(Stack PtrS)
{
if (PtrS->Top == -1)
{
printf("堆栈空");
return ERROR;
}
else
{
return(PtrS->Data[PtrS->Top]--);
}
}
数据结构--栈
最新推荐文章于 2024-11-06 08:56:39 发布