}
main()
{
TYPE * head,*pnum;
int n,num;
printf("input number of node: ");
scanf("%d",&n);
head=creat(n);
print(head);
printf("Input the deleted number: ");
scanf("%d",&num);
head=delete(head,num);
print(head);
printf("Input the inserted number and age: ");
pnum=(TYPE *)malloc(LEN);
scanf("%d%d",&pnum->num,&pnum->age);
head=insert(head,pnum);
print(head);
}
本例中,print函數(shù)用于輸出鏈表中各個結(jié)點(diǎn)數(shù)據(jù)域值。函數(shù)的形參head的初值指向鏈表第一個結(jié)點(diǎn)。在while語句中,輸出結(jié)點(diǎn)值后,head值被改變,指向下一結(jié)點(diǎn)。若保留頭指針head, 則應(yīng)另設(shè)一個指針變量,把head值賦予它,再用它來替代head。在main函數(shù)中,n為建立結(jié)點(diǎn)的數(shù)目, num為待刪結(jié)點(diǎn)的數(shù)據(jù)域值;head為指向鏈表的頭指針,pnum為指向待插結(jié)點(diǎn)的指針。 main函數(shù)中各行的意義是: