//建立一個有三名學(xué)生數(shù)據(jù)的單向動態(tài)鏈表#include<stdio.h>#include<malloc.h>#define NULL 0#define LEN sizeof(struct student)struct student{ long num; float score; struct student *next;};int n;struct student *creat(void)/*定義函數(shù)。此函數(shù)帶回一個指向鏈表頭的指針*/{ struct student *head; struct student *p1,*p2; n=0; p1=p2=(struct student *)malloc(LEN);/*開辟一個新單元*/ scanf("%ld,%f",&p1->num,&p1->score); head=NULL; while(p1->num!=0) { n=n+1; if(n==1) head=p1; else p2->next=p1; p2=p1; p1=( struct student * )malloc(LEN); scanf("%ld,%f",&p1->num,&p1->score); } p2->next=NULL; return(head);}//為什么可以直接寫( struct student * ),還有malloc這個函數(shù)大神能為我舉個例子說明一下嗎
請大神為我解釋一下建立一個三名學(xué)生數(shù)據(jù)的單向動態(tài)鏈表
三十二應(yīng)遍塵剎
2017-03-26 22:04:39