#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;
}

 

posted on 2020-02-27 14:31  笨宝宝  阅读(142)  评论(0编辑  收藏  举报