#include<stdio.h>
#include<malloc.h>
#define LEN sizeof(linkstack)
typedef struct node
{
int data;
struct node *next;
}linkstack;
linkstack *push(linkstack *top,int x);
void print(linkstack *top);
void main()
{
linkstack *top=(struct node*)malloc(LEN);
top->next=NULL;
top->data=-99;
int x;
printf("请输入数据:");
scanf("%d",&x);
top=push(top, x);
//push函数中的传入的top指针,修改其内容是完全OK的;但是修改top指针的地址top=p会没有效果,为了解决这个问题,要用返回值解决问题!!
linkstack *push(linkstack *top,int x)
{
linkstack *p;
p=(struct node *)malloc(LEN);
p->data=x;
p->next=top;
top=p;
return(top);
}void print(linkstack *top)
{
linkstack *t;
t=top;
while(t->next!=NULL)
{
printf("%d\t",t->data);
t=t->next;
}
}