###前插####
#include <stdio.h>
#include <stdlib.h>
typedef struct node //定义一个节点
{
int data;
struct node *next; //定义一个指向下一个指针的节点
}Node;
Node *creatStack() //创建一个栈
{
Node *head=NULL; //定义头指针
Node *p=NULL;
int Data;
scanf("%d",&Data);
while(Data>0) //输入0结束
{
p = (Node *)malloc(sizeof(Node)); //为节点p申请内存
p->data = Data;
p->next = NULL;
if(head==NULL) head = p; //将head指针指向p
else
{
p->next = head;
head = p;
}
scanf("%d",&Data);
}
return head; //返回头指针
}
void Print(Node *head) //打印
{
if(head==NULL) return ;
while(head)
{
printf("%d\n",head->data);
head = head->next;
}
}
int main()
{
Node *head = creatStack();
Print(head);
return 0;
}