【发布时间】:2016-02-06 20:12:19
【问题描述】:
我从数组创建树的代码:
#include<stdio.h>
#include<malloc.h>
typedef struct
{
struct node* left;
struct node* right;
int val;
}node;
void create_tree(node** root,int val)
{
if(*root == NULL )
{
*root = (node*)malloc(sizeof(node));
(*root)->val = val;
(*root)->left = NULL;
(*root)->right = NULL;
return;
}
if((*root)->val <= val )
create_tree(&((*root)->left),val);
else
create_tree(&((*root)->right),val);
return ;
}
int main()
{
node *root = (node*)malloc(sizeof(node));
root->val = 10;
root->left = NULL;
root->right = NULL;
int val[] = { 11,16,6,20,19,8,14,4,0,1,15,18,3,13,9,21,5,17,2,7,12};
int i;
for(i=0;i<22;i++)
create_tree(&root,val[i]);
return 0;
}
我收到的警告:
tree.c:10:6: note: expected ‘struct node **’ but argument is of type ‘struct node **’
void create_tree(node** root,int val)
^
我无法理解此警告的含义?预期和实际都是struct node ** 类型。是bug吗?
【问题讨论】:
-
@Olaf:现在我认为是正确的