#include#include typedef struct node{ int data; struct node* pnext;}node,*pnode;typedef struct stack{ pnode ptop; pnode pbottom;}stack,*pstack;void initstack(pstack ps);void push(pstack ps , int idata);void pop(pstack ps);void traverse(pstack ps);int main(){ pstack S = (pstack)malloc(sizeof(stack)); push(S,1); push(S,2); push(S,3); traverse(S); pop(S); pop(S); traverse(S); return 0;}void initstack(pstack ps){ ps -> ptop = (pnode) malloc(sizeof(node)); if(NULL == ps -> ptop){ puts("error!"); exit(-1); } ps -> pbottom = ps -> ptop ; ps -> ptop -> pnext = NULL;}void push(pstack ps,int idata){ pnode pnew = (pnode)malloc(sizeof(node)); if(NULL == pnew){ puts("error!"); exit(-1); } pnew->data = idata; pnew->pnext = ps->ptop; ps->ptop = pnew;}void traverse(pstack ps){ pnode p = ps->ptop; while(p != ps->pbottom){ printf("%d ",p->data); p = p->pnext; } puts("");}int empty(pstack ps){ if(NULL == ps->ptop) return 1; else return 0;}void pop(pstack ps){ if(empty(ps)){ puts("error!"); exit(-1); } pnode p = ps->ptop; ps->ptop = p->pnext; free(p);}