#include <stdio.h> #include <stdlib.h> typedef struct LinkStack { int info; struct LinkStack *next; }StackNode; typedef struct LinkTop { struct LinkStack *Top; }LinkTop; LinkTop* creat_Stack(void) { LinkTop *p=(LinkTop *)malloc(sizeof(LinkTop)); p->Top=NULL; return p; } int isEmpty( LinkTop p ) { if(p.Top==NULL) return 1; else return 0; } void push_link( LinkTop *p , int e ) { StackNode *s=(StackNode *)malloc(sizeof(StackNode)); s->info=e; s->next=p->Top; p->Top=s; } void pop_link( LinkTop*p ,int *e ) { StackNode *s=NULL; if(p->Top==NULL) return; *e=p->Top->info; s=p->Top; p->Top=s->next; free(s); } int top_link( LinkTop *p ) { if(p->Top==NULL) return -1; return p->Top->info; } void main() { LinkTop *ls=creat_Stack(); int i,j; for(i=0;i<10;i++) { push_link(ls,i); printf("%d ",top_link(ls)); } puts("\n"); for(i=0;i<10;i++) { pop_link(ls,&j); printf("%d,%d\n",j,top_link(ls)); } }
原文地址:http://blog.csdn.net/a781558066/article/details/43702903