#include <iostream>
using namespace std;
#define MaxSize 10
typedef struct
{
int data[MaxSize];
int top;
}SqStack;//sequence
//初始化栈
void InitStack(SqStack& s)
{
//初始化栈顶指针
s.top = -1;
}
//判断栈空
bool StackEmpty(SqStack s)
{
if (s.top == -1) return true;
else return false;
}
//压栈
bool Push(SqStack& s, int value)
{
if (s.top == MaxSize - 1)
{
cout << "栈达到了最大容量" << endl;
return false;
}
s.top = s.top + 1;
s.data[s.top] = value;
return true;
}
//出栈操作
bool Pop(SqStack& s, int& value)
{
if (s.top == -1)
{
cout << "栈为空栈" << endl;
return false;
}
value = s.data[s.top];
s.top -= 1;
}
//获取栈顶元素
int GetTOP(SqStack s)
{
if (s.top == -1)
{
cout << "栈为空栈" << endl;
}
int topValue = s.data[s.top];
return topValue;
}
int main()
{
std::cout << "Hello World!\n";
}
顺序栈
最新推荐文章于 2025-03-19 06:06:30 发布