要素の後と要素の前にいくつかのデータを追加するためにリンクされたリストを作成している間、チュートリアルから学んだように、次の関数を使用しています:
struct node *addafter(struct node *start,int data,int item)
{
struct node *tmp,*p;
p=start;
while(p!=NULL)
{
if(p->info==item)
{
tmp=(struct node *)malloc(sizeof(struct node));
tmp->info=data;
tmp->link=p->link;
p->link=tmp;
return start;
}
p=p->link;
}
printf("Item Not Found:\n");
return start;
}
struct node *addbefore(struct node *start,int data,int item)
{
struct node *tmp,*p;
if(item==start->info)
{
tmp=(struct node *)malloc(sizeof(struct node));
tmp->link=start->link;
tmp->info=data;
start->link=tmp;
return start;
}
p=start;
while(p->link!=NULL)
{
while(p->link->info==item)
{
tmp=(struct node *)malloc(sizeof(struct node));
tmp->info=data;
tmp->link=p->link;
p->link=tmp;
return start;
}
p=p->link;
}
printf("Item Not Found:\n");
return start;
}
私の疑問は、停止条件が p!=NULL である addafter 関数にあり、addbefore 関数の場合、その p->link!=NULL?..誰か説明してください!