ahua的头发

导航

数据结构::线性表实现栈

数据结构::线性表实现栈

 

 

 

#include <iostream>

using namespace std;
#define MaxSize 10
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;
    else
        return false;
}

bool Push(Sqstack &S,int x)
{
    if(S.top == MaxSize-1)
        return false;
    S.data[++S.top]=x;
    return true;
}

bool Pop(Sqstack &S,int &x)
{
    if(S.top==-1)
        return false;
    x=S.data[S.top--];
    return true;
}

bool GetPop(Sqstack S,int &x)
{
    if(S.top==-1)
        return false;
    x=S.data[S.top];
    return true;
}

int main()
{
    Sqstack S;
    InitStack(S);
    cout<<Push(S,3);
    cout<<Push(S,2);
    int x;
    Pop(S,x);
    cout<<x<<endl;
    return 0;
}

 

posted on 2020-06-09 15:11  ahua的头发  阅读(139)  评论(0编辑  收藏  举报