一、结构体定义

1.顺序栈

typedef struct
{
	int data[maxSize];
	int top;
}SqStack;

2.链栈*

typedef struct LNode
{
	int data;
	struct LNode *next;
}LNode;

二、操作

1.栈空

int isEmpty(SqStack st)
{
	return st.top==-1?1:0;
}

2.进栈

int push(SqStack &st,int x)
{
	if(st.top==maxSize-1) 
		return 0;
	st.data[++st.top]=x;
	return 1;
}

3.出栈

int pop(Sqstack &st,int &x)
{
	if(st.top==-1) 
		return 0;
	x=st.data[top--];
	return 1;
}
posted @ 2022-08-26 23:28  unravel_CAT  阅读(10)  评论(0)    收藏  举报