我的头文件中有以下内容
typedef struct tree_node* TreeNode;
struct tree_node{
int value;
void *data;
TreeNode parent;
TreeNode left;
TreeNode right;
};
要创建一个树节点,我正在执行以下操作
TreeNode createTreeNode(int value, void *data){
TreeNode node;
node = malloc(sizeof(TreeNode*));
if(node == NULL){
printf("TreeNode malloc failed!!\n");
exit(EXIT_FAILURE);
}
node->data = data;
node->value = value;
node->parent = NULL;
node->right = NULL;
node->left = NULL;
return node;
}
现在我想创建 TreeNodes 数组......我该怎么做?我在想以下
TreeNode *treeNodes;
treeNodes = malloc(26 * sizeof(TreeNode));
进而
treeNodes[a_number_between_0_to_25] = createTreeNode(intNodeValue, NULL);