初学,如何删除单链表
#include<stdio.h>#include<stdlib.h>
#include<malloc.h>
#include<string.h>
#define N 3
#define LEN sizeof(struct grade)
struct grade
{
char no[7];
int score;
struct grade *next;
};
struct grade *create(void)
{
struct grade *head=NULL,*new1,*tail;
int i=1;
for(;i<=N;i++)
{
new1=(struct grade *)malloc(LEN);
printf("Input the number of student NO.%d(6 bytes):",i);
scanf("%s",new1->no);
if(strcmp(new1->no,"000000")==0)
{
free(new1);
break;
}
printf("Input the score of student NO.%d:",i);
scanf("%d",&new1->score);
if(i==1) head=new1;
else tail->next=new1;
tail=new1;
}
return(head);
}
struct grade *del(struct grade *head)
{
struct grade *p1;
struct grade *p2;
p1=head;
while(p1)
{
p2=p1->next;
free(p1);
p1=p2;
}
};
void main()
{
struct grade *p;
p=del();
if(p==NULL)
printf("链表删除成功");
}
不太会,,求大神