栈-顺序栈

#include<iostream>
#include<vector>

using namespace std;

//结构定义
#define maxSize 50
typedef struct{
    int data[maxSize];
    int top;
}SqStack;

void initStack(SqStack &S){
    S.top = -1;
}

bool StackEmpty(SqStack S){
    if(S.top == -1){
        return true;
    }
    return false;
}

bool Push(SqStack &S,int elem){
    //判断是否栈满
    if(S.top + 1 == maxSize){
        return false;
    }
    S.data[++top] = elem;
    return true;
}

bool Pop(SqStack &S,int &elem){
    //判断是否栈空
    if(S.top == -1){
        return false;
    }
    elem =S.data[top--];
    return true;
}

bool GetTop(SqStack &S,int &elem){
    //判断是否栈空
    if(S.top == -1){
        return false;
    }
    elem = S.data[top];
    return true;
}
原文地址:https://www.cnblogs.com/buaaZhhx/p/12372017.html