//栈的顺序存储
/*
栈顶指针:S.top,
初始时:S.top=-1;
栈顶元素:S.data[S.top]
进栈操作:栈非空的时候,先将栈顶指针减1,再将栈顶元素进去
出栈操作:栈非空的时候,先取栈顶元素,再将栈顶指针减1。
栈空条件:S.top==-1;栈满条件:S.top==MaxSize-1;栈长:S.top+1;
所以,S.top为当前指针所在的位置
S.data[S.top]才是当前指针,即首处的数据。
注意,此处,栈顶指针指的就是栈顶元素,若栈顶指针指的是栈顶元素的下一个元素,则入栈,进栈,判断栈空栈满的条件都会发生改变。
*/
#include<iostream>
using namespace std;
#define MaxSize 50 //定义栈中元素的最大个数
typedef int Elemtype;
typedef struct{
Elemtype data[MaxSize]; //存放栈中的元素,以数组的形式,所以取得时候是data[i]
int top; //栈顶指针
}sqStack;
sqStack s;
int main(){
//初始化栈
s.top = -1;
}
//判断栈是否是空
bool isEmpty(sqStack s){
if (s.top == -1)
return true;
else
return false;
}
//进栈操作
bool inStack(sqStack s,int e){
if (s.top == MaxSize - 1)
return false;
s.top++;
s.data[s.top] == e;
return true;
}
//出栈操作
bool outStack(sqStack s){
if (s.top == -1)
return false;
int tmp;
tmp = s.data[s.top];
s.top--;
}
//读栈中元素
bool readStack(sqStack s){
if (s.top == -1)
return false;
int x = s.data[s.top];
cout << "首地址的元素为:" << endl;
}
/*
栈顶指针:S.top,
初始时:S.top=-1;
栈顶元素:S.data[S.top]
进栈操作:栈非空的时候,先将栈顶指针减1,再将栈顶元素进去
出栈操作:栈非空的时候,先取栈顶元素,再将栈顶指针减1。
栈空条件:S.top==-1;栈满条件:S.top==MaxSize-1;栈长:S.top+1;
所以,S.top为当前指针所在的位置
S.data[S.top]才是当前指针,即首处的数据。
注意,此处,栈顶指针指的就是栈顶元素,若栈顶指针指的是栈顶元素的下一个元素,则入栈,进栈,判断栈空栈满的条件都会发生改变。
*/
#include<iostream>
using namespace std;
#define MaxSize 50 //定义栈中元素的最大个数
typedef int Elemtype;
typedef struct{
Elemtype data[MaxSize]; //存放栈中的元素,以数组的形式,所以取得时候是data[i]
int top; //栈顶指针
}sqStack;
sqStack s;
int main(){
//初始化栈
s.top = -1;
}
//判断栈是否是空
bool isEmpty(sqStack s){
if (s.top == -1)
return true;
else
return false;
}
//进栈操作
bool inStack(sqStack s,int e){
if (s.top == MaxSize - 1)
return false;
s.top++;
s.data[s.top] == e;
return true;
}
//出栈操作
bool outStack(sqStack s){
if (s.top == -1)
return false;
int tmp;
tmp = s.data[s.top];
s.top--;
}
//读栈中元素
bool readStack(sqStack s){
if (s.top == -1)
return false;
int x = s.data[s.top];
cout << "首地址的元素为:" << endl;
}