链栈问题——有源码
源码:
#include<stdio.h>#include<malloc.h>typedef struct node{int data;struct node *next;}StackNode,*LinkStack;/*置空栈*/LinkStack Init_LinkStack(){return NULL;}/*判空栈*/int Empty_ListStack(LinkStack top){if(top==NULL) return 1;else return 0;}/*入栈*/LinkStack Push_LinkStack(LinkStack top,int data){StackNode *s;s=malloc(sizeof(StackNode));s->data=data;s->next=top;top=s;return top;}void main(){LinkStack L;L=malloc(sizeof(LinkStack));L->next=NULL;Push_LinkStack(L,20);printf("%d\n",L->data);}
#include<stdio.h>#include<malloc.h>typedef struct node{ int data; struct node *next;}StackNode,*LinkStack;/*置空栈*/LinkStack Init_LinkStack(){ return NULL;}/*判空栈*/int Empty_ListStack(LinkStack top){ if(top==NULL) return 1; else return 0;}/*入栈*/LinkStack Push_LinkStack(LinkStack top,int data){ StackNode *s; s=(StackNode*)malloc(sizeof(StackNode)); s->data=data; s->next=top;top=s; return top;}void main(){ LinkStack L,top; L=(LinkStack)malloc(sizeof(LinkStack)); L->next=NULL; top=Push_LinkStack(L,20); printf("%d\n",top->data);}