#include #include #include #include typedef int DataType;typedef struct node{ DataType data; struct node* pNext;}*PNode,Node;typedef struct linkStack{ PNode top; size_t sz;}*LinkStack;LinkStack creat(){ LinkStack lstack = (LinkStack)malloc(sizeof(struct linkStack)); if (NULL == lstack) { exit(0); } lstack->top = nullptr; lstack->sz = 0; return lstack;}int IsEmpty(LinkStack lstack){ assert(lstack); if (nullptr == lstack->top || 0 == lstack->sz) { return 1; } return 0;}PNode getTop(LinkStack lstack){ if (lstack->sz == 0) { return nullptr; } return lstack->top;}int getSize(LinkStack lstack){ assert(lstack); return lstack->sz;}void PushStack(LinkStack lstack, DataType data){ assert(lstack); PNode newNode = (PNode)malloc(sizeof(Node)); if (NULL == newNode) { printf("内存分配失败!!"); exit(0); } newNode->data = data; newNode->pNext = getTop(lstack); lstack->top = newNode; lstack->sz++;}PNode PopStack(LinkStack lstack){ if (IsEmpty(lstack)) { return NULL; } PNode node = lstack->top; lstack->top = lstack->top->pNext; --(lstack->sz); return node;}void DestroyStack(LinkStack lstack){ if (IsEmpty(lstack)) { free(lstack); lstack = nullptr; printf("链栈已空,无需删除\n"); return; } do { PNode pTemp; pTemp = PopStack(lstack); free(pTemp); } while (lstack->sz > 0); printf("链栈销毁成功");}int main(){ LinkStack lstack = creat(); PushStack(lstack, 10); PushStack(lstack, 20); PushStack(lstack, 60); PushStack(lstack, 70); PushStack(lstack, 40); while (lstack->sz > 0) { printf("%d\t", PopStack(lstack)->data); } system("pause");}