关于创建一个链表的简单问题!!
#include "stdafx.h"#include "stdlib.h"
struct Student{
int num;
Student* next;
};
int main()
{
Student* Head = NULL;
Head = (Student*)malloc(sizeof(Head));
if( Head == 0)
return 0;
Head->next = NULL;
Student* link = NULL;
int a[5] = {1,2,3,4,5};
for(int j = 0;j < 5;j++)
{
link = (Student*)malloc(sizeof(link));
link->num = a[j];
link->next = Head->next;
Head->next = link;//从这开始的下一步为什么不需要向指针一样指向下一个单元
}
for(int i = 1;i <= 5;i++)
{
printf("%d->",link->num);
link = link->next;
}
return 0;
}