链栈的输入输出操作,可以输入但是没有输出
#include <stdio.h>
#include <stdlib.h>
typedef struct stacknode {
int data;
struct stacknode *next;
} stacknode;
int initiate(stacknode *top) {
top=(stacknode*)malloc(sizeof(stacknode));
top=NULL;
return 0;
}
int push(stacknode *top, int x) {
stacknode* s = (stacknode *)malloc(sizeof(stacknode));
s->data = x;
s->next = top;
top = s;
return 0 ;
}
int pop(stacknode *top) {
if (top == NULL)
return NULL;
stacknode *s;
s = top;
int z=s->data;
top = top->next;
if(top==NULL){
return NULL;
}
free(s);
return z;
}
int main() {
int i,j,x,m=0;
stacknode top;
initiate(&top);
for(i=0;i<5;i++){
scanf("%d",&x);
push(&top,x);
}
for(j=0;j<5;j++){
int m=pop(&top);
printf("%d",m);
}
return 0;
}