我讀到那些關於樹在C:爲什麼在C結構中使用兩個指針
struct node
{
int key_value;
struct node *left;
struct node *right;
};
/* insert a value to tree */
insert(int key, struct node **leaf)
{
if(*leaf == 0)
{
*leaf = (struct node*) malloc(sizeof(struct node));
(*leaf)->key_value = key;
/* initialize the children to null */
(*leaf)->left = 0;
(*leaf)->right = 0;
}
else if(key < (*leaf)->key_value)
{
insert(key, &(*leaf)->left);
}
else if(key > (*leaf)->key_value)
{
insert(key, &(*leaf)->right);
}
}
我不明白這裏:插入(INT鍵,結構節點**葉)爲什麼兩個指針**葉,葉子好嗎?我很困惑什麼時候使用兩個指針.pls幫助,非常感謝!
這是一個指向'struct node *'的指針。 – immibis
這看起來像一棵二叉樹,如果是這樣,你的左右節點或「樹葉」就是子分支。 –
**備註:** **葉;它不被稱爲「雙指針」。它被稱爲「指針指針」 – sami1592