题目
题目
单项选择题

Which XXX completes the C++ AVLTree class's Insert() function? void Insert(Node* node) { if (!root) { root = node; } else { Node* currentNode = root; while (currentNode) { if (node->key < currentNode->key) { if (currentNode->left == nullptr) { currentNode->left = node; node->parent = currentNode; currentNode = nullptr; } else { currentNode = currentNode->left; } } else { if (currentNode->right == nullptr) { currentNode->right = node; node->parent = currentNode; currentNode = nullptr; } else { currentNode = currentNode->right; } } } XXX while (node) { Rebalance(node); node = node->parent; } } }

查看解析

查看解析

标准答案
Please login to view
思路分析
The question asks what should fill the XXX in the AVLTree Insert function after linking the new node into the tree. First, note what the code does: it inserts the new node as a leaf, setting its parent appropriately, and then reaches the XXX placeholder. After insertion, rebalancing must propagate from the newly inserted node up toward the root, since AVL trees require balancing based on the ancestors of the inse......Login to view full explanation

登录即可查看完整答案

我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。

更多留学生实用工具

加入我们,立即解锁 海量真题独家解析,让复习快人一步!