【发布时间】:2016-01-07 04:28:18
【问题描述】:
我有一个 C 编程问题。下面是使用键插入节点。
我不明白为什么node->left = insert(node->left,key)
我假设这段代码会用什么更新node->left?
不是又在打电话insert()吗?就像一次又一次地调用同一个函数不是无限循环还是insert调用?
我检查了几个例子,他们都是通过再次调用相同的函数来更新node->left?假设我误解了,里面的存储是什么?指针?还是它们只是神奇地联系在一起?
// An AVL tree node
struct node
{
int key;
struct node *left;
struct node *right;
int height;
};
struct node* insert(struct node* node, int key)
{
/* 1. Perform the normal BST rotation */
if (node == NULL)
return(newNode(key));
if (key < node->key)
node->left = insert(node->left, key);//This just called Insert function again?
else
node->right = insert(node->right, key);
【问题讨论】:
标签: c algorithm binary-tree avl-tree