我想实现单链表的建立, 可下面程序为什么会出现死循环呀??? 各位帮我看看
实现一个单链表的建立
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<conio.h>
using namespace std;
typedef struct student
{
int data;
struct student *next;
}node;
node *create()
{
node *head, *p, *s;
int x,cycle=1;
head=(node*)malloc(sizeof(node));
p=head;
while(cycle)
{
printf("\nplease input the data: ");
scanf("%d",&x);
if(x!=0)
{
s=(node*)malloc(sizeof(node));
s->data=x;
printf("\n %d",s->data);
p->next=s->next;
s->next=p;
}
else cycle=0;
}
head = head->next;
p->next=NULL;
printf("\n YYY %d",head->data );
return(head);
}
int main(void)
{
node *head;
head=create();
return 0;
}