本文整理汇总了C++中BaseNode::getChildren方法的典型用法代码示例。如果您正苦于以下问题:C++ BaseNode::getChildren方法的具体用法?C++ BaseNode::getChildren怎么用?C++ BaseNode::getChildren使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BaseNode
的用法示例。
在下文中一共展示了BaseNode::getChildren方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: singlePoint
Tree<T>* singlePoint(const Tree<T>* left, const Tree<T>* right) {
auto tree = left->clone(); // Copy left
auto treeDepth = right->getDepth();
auto depth = utils::random_uint(treeDepth);
auto sourceNode = right->root; // Crossover from the right to the left
BaseNode<T>* prevSourceNode = nullptr;
for (unsigned int i = 0; i < depth; ++i) {
if (sourceNode->getChildren().empty()) {
sourceNode = prevSourceNode; // Do not copy terminators
break;
}
prevSourceNode = sourceNode;
sourceNode = sourceNode->getChildren()[utils::random_uint(
sourceNode->getChildren().size())];
}
auto currentNode = tree->root;
BaseNode<T>* prevNode = nullptr;
for (unsigned int i = 0; i < depth; ++i) {
prevNode = currentNode;
auto nextNodeLocation =
utils::random_uint(currentNode->getChildren().size());
currentNode = currentNode->getChildren()[nextNodeLocation];
if (sourceNode->getDepth() == currentNode->getDepth()) {
auto& children = prevNode->getChildren();
delete currentNode;
children[nextNodeLocation] = sourceNode->clone();
break;
} else if (currentNode->getChildren().empty()) {
break; // This point should never be reached
}
}
return tree;
}