#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";
}
07-17
07-17
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交