填空題

設線性鏈表的存儲結構如下:
struct node
{ELEMTP data; /*數據域*/
struct node *next; /*指針域*/
}
試完成下列在鏈表中值為x的結點前插入一個值為y的新結點。如果x值不存在,則把新結點插在表尾的算法。
void inserty(struct node *head,ELEMTP x,ELEMTP y)
{s=(struct node *)malloc(sizeof(struct node));
();
if(){s->nexr=head;head=s;}
else {
q=head;p=q->next;
while(p->dqta!=x&&p->next!=NULL){q=p;()}
if(p->data= = x){q->next=s;s->next=p;}
else{p->next=s;s->next=NULL;}
}
}

答案: s->data=y;head->data= =x;p=p->next
微信掃碼免費搜題