#include <iostream> #include <malloc.h> using namespace std; const int maxn=500; typedef struct { int data[maxn]; int top; }Stack; //初始化stack void init(Stack *&s) { s=(Stack *)malloc(sizeof(Stack)); s->top=-1; } //销毁stack void destroy(Stack *&s) { free(s); } //判断栈是否为空 bool empty(Stack *s) { return (s->top==-1); } //进stack void push(Stack *&s,int e) { if(s->top==maxn-1) { cout<<"栈满,不能插入!"<<endl; return ; } s->top++; s->data[s->top]=e; } //出stack void pop(Stack *&s,int get) { if(s->top==-1) { cout<<"栈为空,没有元素出栈!"<<endl; return ; } get=s->data[s->top]; s->top--; } //获取栈顶元素 int top(Stack *&s,int get) { if(s->top==-1) { cout<<"栈为空,没有元素出栈!"<<endl; return 0 ; } get=s->data[s->top]; return get; } int main() { return 0; }