我在递归循环中创建了分段错误,但不明白为什么。有人可以帮助我吗?
struct node{
int value;
int order;
struct node *left;
struct node *right;
};
typedef struct node node_t;
node_t array[10];
void createTree(node_t **p, int order){
(*p)->value = rand()%10;
(*p)->order = order;
printf("%i", (*p)->value);
printf(" ");
printf("%i\n", (*p)->order);
if (!order){
(*p)->left = NULL;
(*p)->right = NULL;
return;
}
//I believe that here is the origin of the problem...
createTree(&(*p)->left, order-1);
createTree(&(*p)->right, order-1);
}
int main(void)
{
node_t *root = &array[0];
srand(time(NULL));
createTree(&root, 1);
printf("%i\n", root->value);
return 1;
}