私はhttp://www.cprogramming.com/snippets/source-code/singly-linked-list-insert-remove-add-countを経由して、このコードを発見したC.にリンクリストと位置によって挿入理解しようとしています:理解挿入
void addafter(int num, int loc)
{
int i;
struct node *temp,*left,*right;
right=head;
for(i=1;i<loc;i++)
{
left=right;
right=right->next;
}
temp=(struct node *)malloc(sizeof(struct node));
temp->data=num;
left->next=temp;
left=temp;
left->next=right;
return;
}
それはコンパイルし、正常に動作しますが、しかし、私は理解していませんこの部分:
left->next=temp;
left=temp;
left->next=right;
左の次のノードポインタがtempを指している場合、left = tempで上書きされませんか?
left->next=temp;
temp->next=right
これを私に説明してもらえますか?ありがとうございました。
の上にあなたのコードの一部を変更したい場合があります。 –
なぜleft = tempを使うのですか? – user3283146
それはあなたが作者に尋ねる必要があるので、他の誰も答えることはできない。私自身は何の理由も見ません。 –