其他分享
首页 > 其他分享> > 链栈的实现

链栈的实现

作者:互联网

#include"iostream"
using namespace std;
#define OK 1
#define ERROR 0
typedef struct StackNode
{
	int data;
	struct StackNode *next;
}StackNode,*LinkStack;
int InitStack(LinkStack &s)
{
	s = NULL;
	return OK;
}
int Push(LinkStack &s,int e)
{
	LinkStack p;
	p = new StackNode;
	p->data = e;
	p->next = s;
	s = p;
	return OK;
}
int Pop(LinkStack &s)
{
	if (s == NULL)
		return ERROR;
	cout << s->data << endl;
	LinkStack p;
	p = s;
	s = s->next;
	delete p;
	return OK;
}
int main()
{
	int n;
	LinkStack s;
	InitStack(s);
	cout << "链栈中有多少元素" << endl;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int e;
		cin >> e;
		Push(s, e);
	}
	Pop(s);
	system("pause");
	return 0;
}

标签:LinkStack,return,实现,next,链栈,int,StackNode,OK
来源: https://blog.csdn.net/weixin_54042669/article/details/119038279