编辑代码

#include <bits/stdc++.h>
using namespace std;
const int maxn=101;
typedef struct{
    int data[maxn];
    int top;
}Stack;
void init(Stack &S){
    S.top=-1;
}
bool push(Stack &S,int e){
    if(S.top==maxn)return false;
    S.data[++S.top]=e;
    return true;
}
bool pop(Stack &S,int &e){
    if(S.top==-1)return false;
    e=S.data[S.top--];
    return true;
}
int getTop(Stack S){
    if(S.top==-1)return false;
    return S.data[S.top];
}
bool isEmpty(Stack S){
    return S.top==-1;
}
int main() {
    Stack S;
    init(S);
    push(S,1);
    push(S,2);
    cout<<getTop(S);
	return 0;
}