数据结构 顺序栈 C\C++实现

版权声明:转载请注明原文地址即可,要是本文对您有些许帮助的话,请您在下方点个赞,谢谢啦ヾ(o◕∀◕)ノヾ https://blog.csdn.net/qq_33583069/article/details/89765759

顺序栈

#include<iostream> 
using namespace std;
#define MAX 100
typedef int ElemType;
typedef struct stack{
	ElemType data[MAX];
	int top,stackSize;
}Stack;
void init(Stack &st){st.top=-1;}
int empty(Stack& st){return st.top==-1;}
void push(Stack& st,int x){
	if(st.top==MAX)cout<<"Error";
	else st.data[++top]=x;
}
int pop(Stack& st){
	if(empty(st))cout<<"Error";
	else return st.data[top--];
}

猜你喜欢

转载自blog.csdn.net/qq_33583069/article/details/89765759