int bitree_ins_left(BiTree *tree, BiTreeNode *node, const void *data)
{
BiTreeNode *new_node, **position; //这里为什么要二重指针? *position不行吗?
if( node == NULL )
{
if( bitree_size(tree) > 0 )
return -1;
position = &tree->root;
}
else
{
if( bitree_left(node) != NULL )
return -1;
position = &node->left;
}
/* Allocate storage for the node */
new_node = (BiTreeNode *)malloc(sizeof(BiTreeNode));
if( new_node == NULL )
return -1;
/* insert the node into the tree */
new_node->data = (void *)data;
new_node->left = NULL;
new_node->right = NULL;
*position = new_node;
//Adjust the size of the tree to account for the inserted node.
//上面的account for是什么意思?
tree->size++;
return 0;
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
目测楼主看的应该是我大天朝的C语言数据结构丛书吧。再目测一下这里的struct BiTreeNode里面应该有一个叫struct BiTreeNode next的成员吧。那为什么还要写个struct BiTreeNode *position呢?大概这就是程序员版的画蛇添足!
至于这句话Adjust the size of the tree to account for the inserted node.,我英语学的也不太好,大概to account for the inserted node这个从句是用来修饰前面那个tree的,但这句话后面有个语句tree->size++;我很清楚,这不就是插入结点后更新树的大小吗?