C语言栈的基本 *** 作

C语言栈的基本 *** 作,第1张

#include 
#include 
#define MaxSize 20
typedef struct {
	int data[MaxSize];//数组
	int top;//栈顶
}SqStack;//顺序栈存储类型
void InitStack(SqStack s) {
	s.top = -1;
}//初始化
bool StackEmpty(SqStack s) {
	if (s.top != 1) {
		return false;
	}
	else
		return true;
}//判空
bool push(SqStack s, int x) {
	if (s.top == MaxSize - 1) {
		return false;//栈已满
	}
	else {
		s.data[s.top + 1] = x;
		s.top = s.top + 1;
		//s.data[++s.top]=x;
	}
	return true;
}//进栈
bool pop(SqStack s, int x) {
	if (s.top == -1) {
		return false;
	}
	else
		s.data[s.top--] = x;
	return true;
}//出栈

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/786033.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-04
下一篇2022-05-04

发表评论

登录后才能评论

评论列表(0条)

    保存