stack.cpp
来自「这是关于二叉树的建立」· C++ 代码 · 共 39 行
CPP
39 行
#include <iostream.h>
#include "stack.h"
void InitStack(SeqStack *S)
{//将顺序栈置空
S->top = -1;
}
int StackEmpty(SeqStack *S)
{
return S->top == -1;
}
int StackFull(SeqStack *S)
{
return S->top == StackSize-1;
}
void Push(SeqStack *S,DataType x)
{
if (StackFull(S))
cout<<"栈已满!"<<endl; //上溢,退出运行
S->data[++S->top] = x;//栈顶指针加1后将x入栈
}
DataType Pop(SeqStack *S)
{
if(StackEmpty(S))
cout<<"栈为空"<<endl; //下溢,退出运行
return S->data[S->top--];//栈顶元素返回后将栈顶指针减1
}
DataType StackTop(SeqStack *S)
{
// if(StackEmpty(S))
// cout<<"栈为空"<<endl;
return S->data[S->top];
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?