三种方法总结
struct ListNode *createlist()
{
struct ListNode *head = NULL, *now = NULL;
int num;
while(1)
{
scanf("%d",&num);
if(num == -1){
return head;
}
now = (struct ListNode *)malloc(sizeof(struct ListNode));
now->data = num;
now->next = head;
head = now;
}
}
struct ListNode *createlist()
{
struct ListNode *now, *head,*q;
now=head=NULL;
q = (struct ListNode*)malloc(sizeof(struct ListNode));
now = q;
now->next=head;
while(1)
{
scanf("%d",&now->data);
if(q->data == -1)
{
return head->next;
}
q = (struct ListNode*)malloc(sizeof(struct ListNode));
now=q;
now->next=head;
head=now;
}
}
struct ListNode *createlist()
{
struct ListNode *now, *head,*q;
now=head=NULL;
while(1)
{
q = (struct ListNode*)malloc(sizeof(struct ListNode));
now=q;
now->next=head;
scanf("%d",&now->data);
if(q->data == -1)
{
return head->next;
}
head=now;
}
}