关键在主函数中啊。请看程序后在分析啊,谢谢!!!
#include <stdio.h>
#define max 10
struct list
{
int number;
char name[max];
struct list *next ;
};
typedef struct list node ;
typedef node *link ;
void freelist(link head) /*释放链表 */
{ link pointer ;
while(head !=NULL)
{ pointer=head;
head=head->next ;
free(head);
}
}
void printlist(link head) /*/输出链表 */
{ link pointer;
pointer=head;
while(pointer !=NULL)
{ printf("notice input date : \t");
printf("date number: %d .it's name %s\n",pointer->number,pointer->name);
pointer=pointer->next;
}
}
link creatlist(link head) /*/建立链表 */
{
int datenum ;
char datename[max];
link new1 ,pointer;
int i;
head=(link)malloc(sizeof(node));
if(head==NULL)
printf("failure in alloc \n");
else
{ printf("##the first size is %d\n",sizeof(head));
datenum=1;
printf("please input the date name :\t");
scanf("%s",datename);
head->number=datenum ;
for(i=0;i<max;i++)
head->name[i]=datename[i];
head->next=NULL;
pointer=head;
while(1)
{
datenum++ ;
new1=(link)malloc(sizeof(node));
printf("&&&the next size is %d .\n please input the next date name:\t",sizeof(new1)) ;
scanf("%s",datename) ;
if(datename[0]=='0' )
break;
new1->number=datenum;
for(i=0;i<max;i++)
new1->name[i]=datename[i];
new1->next=NULL;
pointer->next=new1;
pointer=new1;
}
}
return head;
}
void main()
{ link head,pointer;
head=creatlist(head) ;
pointer=head;
printlist(pointer);
freelist(pointer);
getch();
return;
}
其中这段:
pointer=head;
printlist(pointer);
freelist(pointer);中的后两行程序中的pointer和head换与不换有什么区别和影响啊?/?