链表成员赋值
void main(){
int n;
scanf("%d",&n);
head=createcode(n);
head=createnum(head,n);
}
struct student *createcode(int n)
{
struct student *head,*p,*q;
int i=0;
p=(struct student *)malloc(sizeof(struct student));
printf("plase input code:");
scanf("%d",&p->code);
head=p;
p->next=NULL;
p->prior=NULL;
while(1)
{
if(i==n)
break;
i++;
q=(struct student *)malloc(sizeof(struct student));
if(i<n){
printf("plase input code:");
scanf("%d",&q->code);
p->next=q;
q->prior=p;
p=q;
}
}
free(q);
p->next=head;
head->prior=p;
return(head);
}
struct student *createnum(struct student *head,int n)
{
struct student *p,*q;
int i=0,j=2;
p=(struct student *)malloc(sizeof(struct student));
p->num=1;
head=p;
p->next=NULL;
p->prior=NULL;
while(1)
{
if(i==n)
break;
i++;
q=(struct student *)malloc(sizeof(struct student));
if(i<n){
q->num=j;
p->next=q;
q->prior=p;
p=q;
j++;
}
}
free(q);
p->next=head;
head->prior=p;
return(head);
}
为什么给num赋值时,code 里面值不见了