链栈C语言

#include <stdio.h>
#include <stdlib.h>


typedef int eletype;
typedef struct stacknode
{
eletype data;
struct stacknode *next;
}stacknode,*linkstack;
linkstack initstack (){
linkstack S;
S=NULL;
return S;
}

linkstack push(linkstack S)
{
eletype data;
while(scanf("%d",&data) != EOF)
{
stacknode *p;
p=(stacknode*)malloc(sizeof(stacknode));
p->data=data;
p->next=S;
S=p;
}
return S;
}
linkstack pop(linkstack S)
{
int e;
linkstack p;
if(S==NULL){
printf("error empty ");
exit (0);
}
else{
while(!S==NULL){
e=S->data;
printf("%d\n",e);
p=S;
S=S->next;
free (p);

}
}
}
int main ()
{
linkstack *S;
S=initstack();
S=push(S);
pop(S);

}

posted @ 2022-03-20 17:58  zhichutian  阅读(57)  评论(0)    收藏  举报