#include <iostream>
using namespace std;typedef int Elemtype;#define Maxsize 10
#define ERROR 0
#define OK 1typedef struct Linknode
{Elemtype data; struct Linknode *next;
}Linknode,* LinkStack;void InitStack(LinkStack& L)
{L = (LinkStack)malloc(sizeof(Linknode));L->next = NULL;
}bool StackEmpty(LinkStack L)
{if (L->next == NULL) {cout<<"栈为空"<<endl;return ERROR;}else {cout << "栈不为空" << endl;return OK;}
}bool Push(LinkStack &L, Elemtype e)
{Linknode *s = (LinkStack)malloc(sizeof(Linknode));s->data = e;s->next = L->next;L->next = s;return OK;
}bool Pop(LinkStack& L, Elemtype &e)
{if (L->next == NULL){cout << "栈为空" << endl;return ERROR;}Linknode* p = L->next;e = p->data;L->next = p->next;cout << "出栈元素值为: " << e << endl;free(p);return OK;
}bool GetTop(LinkStack& L, Elemtype& e)
{if (L->next == NULL){cout << "栈为空" << endl;return ERROR;}e = L->next->data;cout << "栈顶元素值为: " << e << endl;return OK;
}void PrintStack(LinkStack L)
{Linknode* p= L->next;while (p != NULL){cout << "|______" << p->data << "______|" << endl;p = p->next;}
}
int main(void)
{LinkStack S = NULL;InitStack(S);StackEmpty(S);Push(S, 1);Push(S, 2);Push(S, 3);Push(S, 4);StackEmpty(S);PrintStack(S);int e = 0, x = 0;Pop(S, e);PrintStack(S);GetTop(S, x);
}