关于链表
本人新手。。编了一个链表的程序,可是运行不了。。。求解决。。#include<stdio.h>
#include<malloc.h>
#define NULL 0
struct student
{
int num;
struct student *next;
};
void main()
{
int i;
struct student *head=NULL;
struct student *p1,*p2,*p;
p1=p2=(struct student*)malloc(sizeof(struct student));
head=p1;
p2=p1;
for(i=1;i<=10;i++)
{
p1->num=i;
p1=(struct student*)malloc(sizeof(struct student));
p1=p2->next;
p2=p1;
}
p2->next=NULL;
p=head;
while(p!=NULL)
{
printf("%d\n",p->num);
p=p->next;
}
}