链表的最简单的问题
初学c语言链表,就不幸的卡在了这里注释处为错误;
#include<stdio.h>
#include<stdlib.h>
#include<alloc.h> // Cannot open include file: 'alloc.h': No such file or directory
struct node{
int data;
struct node *next;
}
int main()
{
struct node *head,*p1,*p2;
head =(struct node *)malloc(sizeof(struct node));
p1 =(struct node *)malloc(sizeof(struct node));
p2 =(struct node *)malloc(sizeof(struct node));
head->data=1000;head->next=p1;
p1->data=1001;p1->next=p2;
p2->data=1002;p2->next=NULL;
while (head!=NULL){
printf("%d\n",head->data);
p1=head;
head=head->next;
free(p1);
}
return 0;
}