代码有些疑问,麻烦大家帮我讲解一下
#include "stdafx.h"
#include "stdio.h"
#include "string.h"
#include "malloc.h"
#define NULL 0
#define LEN sizeof(struct stu)
struct stu
{
int num;
struct stu *next;
}*p1,*p2;
struct stu *creat()
{
int temp;
struct stu *head=NULL;
printf("input temp:\n");
scanf("%d",&temp);
while(temp!=0)
{
p1=(struct stu *)malloc(LEN);
if(head==NULL)//这个head=NULL在程序中是什么意思啊?,为什么为空呢?
head=p1;
else
p2->next=p1;
p1->num=temp;
p2=p1;
printf("\ninput number:");
scanf("%d",&temp);
}
p2->next=NULL;
return(head);
}
void output(struct stu *head)
{
for(p1=head;p1!=NULL;p1=p1->next)
{
printf("%4d",p1->num);
}
}
struct stu *turnback(struct stu *head)
{
struct stu *a,*newhead,*temp;
p2=head;
p1=head->next;
head->next=NULL;
while(p1!=NULL)
{
temp=p1->next;
p1->next=p2;
p2=p1;
p1=temp;
}
newhead=p2;
return(newhead);
}
int main(int argc, char* argv[])
{
struct stu *head;
head=creat();
printf("the original list:\n");
output(head);
head=turnback(head);
printf("\nthe new list:\n");
output(head);
printf("\n");
return 0;
}