二重ポインタを使用している連結リストに関する C コードの意味がわかりません。これが私が読んでいるコードです
struct list
{
int value;
struct list *next;
};
//Insert an element at the begining of the linked list
void insertBegin(struct list **L, int val)
{
//What does **L mean?
//Memory allocation for the new element temp
struct list *temp;
temp = (struct list *)malloc(sizeof(temp));
//The new element temp points towards the begining of the linked list L
temp->next = *L;
//Set the beginning of the linked list
*L = temp;
(*L)->value = val;
}
void loop(struct list *L)
{
printf("Loop\n");
//Run through all elements of the list and print them
while( L != NULL )
{
printf("%d\n", L->value);
L = L->next;
}
}
struct list* searchElement(struct list *L,int elem)
{
while(L != NULL)
{
if(L->value == elem)
{
printf("Yes\n");
return L->next;
}
L = L->next;
}
printf("No\n");
return NULL;
}
int main()
{
struct list *L = NULL;
insertBegin(&L,10); // Why do I need
return 0;
}
と**L
はどういうinsertElement
意味ですか? 主にが宣言されているときに、単純ではなく引数を使用して関数を呼び出す必要があるのはなぜですか?**L
*L
loop
struct list *L = NULL
insertBegin
&L
L
*L
リンクされたリストの最初のノードへのポインターであると思いますが**L
、リストの任意の要素を指す場合があります。ただし、これが正しいかどうかはわかりません。
ご協力ありがとうございました!