链表顺序输出疑问
#include "stdio.h"
#include "stdlib.h"
typedef struct Lnode
{
int data;
struct Lnode *next;
}Lnode,*LinkList;
void main()
{
int i = 0;
LinkList L,p,q;
L = (LinkList)malloc(sizeof(Lnode));
if(L == NULL)
{
printf("申请内存空间失败!\n");
exit(0);
}
L->next = NULL;
q = L;
while(i < 5)
{
p = (LinkList)malloc(sizeof(Lnode));
if(p == NULL)
{
printf("申请内存空间失败!\n");
exit(0);
}
p->next = NULL;
printf("请输入数据:\n");
scanf("%d",&p->data);
p->next = q->next;
q->next = p;
q = p;
i++;
}
p = L->next;
while(p)
{
printf("%4d",p->data);
p=p->next;
}
}
请问红色的三条语句是什么意思,求高手解答!
#include "stdlib.h"
typedef struct Lnode
{
int data;
struct Lnode *next;
}Lnode,*LinkList;
void main()
{
int i = 0;
LinkList L,p,q;
L = (LinkList)malloc(sizeof(Lnode));
if(L == NULL)
{
printf("申请内存空间失败!\n");
exit(0);
}
L->next = NULL;
q = L;
while(i < 5)
{
p = (LinkList)malloc(sizeof(Lnode));
if(p == NULL)
{
printf("申请内存空间失败!\n");
exit(0);
}
p->next = NULL;
printf("请输入数据:\n");
scanf("%d",&p->data);
p->next = q->next;
q->next = p;
q = p;
i++;
}
p = L->next;
while(p)
{
printf("%4d",p->data);
p=p->next;
}
}