連結清單是建立
struct Data
{
int num;
int score;
struct Data *next;
};
struct Data *input()
{
struct Data *head,*p1,*p2;
p1=(struct Data*)malloc(LEN);
p2=(struct Data*)malloc(LEN);
n=0;
scanf("%d",&p1->num);
while(p1->num!=0)
{
scanf("%d",&p1->score);
n++;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct Data*)malloc(LEN);
scanf("%d",&p1->num);
}
p2->next=NULL;
return head;
}
連結清單的釋放
void Free_List(struct Data *Head)
{
struct Data *Pointer=NULL;
while (NULL != Head)
{
Pointer = Head;
Head = Head->Next; // 下一個節點
free(Pointer);
}
}
稍後的一些補充