其他分享
首页 > 其他分享> > 堆栈

堆栈

作者:互联网

顺序储存

#include<iostream>
using namespace std;
#define MaxSize 10
const ERROR=0;
const TRUE=1;
typedef int ElemType;
typedef struct Snode
{
	ElemType data[MaxSize];
	int Top;
}Snode;
void Push(Snode *Ptrs,ElemType Item)//入栈
{
	if(Ptrs->Top==MaxSize)
	{
		cout<<"堆栈满";
		return ;
	}
	else
	{
		Ptrs->data[++(Ptrs->Top)]=Item;
		return ;
	}
}
ElemType Pop(Snode *Ptrs,)//出栈
{
	if(Ptrs->Top==-1)
	{
		cout<<"堆栈空";
		return ERROR;
	}
	else
	{
		return (Ptrs->data)[(Ptrs->Top)--];
	}
}

标签:int,ElemType,Top,Ptrs,Snode,MaxSize,堆栈
来源: https://www.cnblogs.com/tokai0teio/p/15849061.html