TNode* RemoveNodesOutOfRange(TNode* root,int min,int max){ if(!root){ return NULL; } root->right=RemoveNodesOutOfRange(root->right,min,max); root->left=RemoveNodesOutOfRange(root->left,min,max); if(root->data < min || root->data > max){ if(root->left && root->right){ TNode* tmpNode=GetLeftMost(root->right); tmpNode->left=root->left; return root->right; } else if(root->left){ return root->left; } else if(root->right){ return root->right; } else{ return NULL; } } return root; }
void touchmind::layout::LayoutManager::Apportion( const std::shared_ptr<touchmind::model::node::NodeModel> &tree, const std::shared_ptr<touchmind::model::node::NodeModel> &node, int level) { UNREFERENCED_PARAMETER(tree); std::shared_ptr<touchmind::model::node::NodeModel> pFirstChild = node->GetFirstChild(); std::shared_ptr<touchmind::model::node::NodeModel> pFirstChildLeftNeighbor = _GetLayoutWorkData(pFirstChild)->pLeftNeighbor; int j = 1; for (int k = m_configuration->GetMaxDepth() - level; pFirstChild != nullptr && pFirstChildLeftNeighbor != nullptr && j <= k;) { FLOAT modifierSumRight = 0.0f; FLOAT modifierSumLeft = 0.0f; std::shared_ptr<touchmind::model::node::NodeModel> pRightAncestor = pFirstChild; std::shared_ptr<touchmind::model::node::NodeModel> pLeftAncestor = pFirstChildLeftNeighbor; for (int l = 0; l < j; ++l) { pRightAncestor = pRightAncestor->GetParent(); pLeftAncestor = pLeftAncestor->GetParent(); modifierSumRight += _GetLayoutWorkData(pRightAncestor)->modifier; modifierSumLeft += _GetLayoutWorkData(pLeftAncestor)->modifier; } FLOAT totalGap = (_GetLayoutWorkData(pFirstChildLeftNeighbor)->prelim + modifierSumLeft + GetNodeSize(pFirstChildLeftNeighbor) + m_configuration->GetSubtreeSeparation()) - (_GetLayoutWorkData(pFirstChild)->prelim + modifierSumRight); if (totalGap > 0) { std::shared_ptr<touchmind::model::node::NodeModel> subTreeAux = node; int numSubtrees = 0; for (; subTreeAux != nullptr && subTreeAux != pLeftAncestor; subTreeAux = subTreeAux->GetLeftSibling()) { numSubtrees++; } if (subTreeAux != nullptr) { std::shared_ptr<touchmind::model::node::NodeModel> subtreeMoveAux = node; FLOAT singleGap = totalGap / numSubtrees; for (; subtreeMoveAux != pLeftAncestor; subtreeMoveAux = subtreeMoveAux->GetLeftSibling()) { _GetLayoutWorkData(subtreeMoveAux)->prelim += totalGap; _GetLayoutWorkData(subtreeMoveAux)->modifier += totalGap; totalGap -= singleGap; } } } j++; if (pFirstChild->GetChildrenCount() == 0) { pFirstChild = GetLeftMost(node, 0, j); } else { pFirstChild = pFirstChild->GetFirstChild(); } if (pFirstChild != nullptr) { pFirstChildLeftNeighbor = _GetLayoutWorkData(pFirstChild)->pLeftNeighbor; } } }
std::shared_ptr<touchmind::model::node::NodeModel> touchmind::layout::LayoutManager::GetLeftMost( const std::shared_ptr<touchmind::model::node::NodeModel> &node, int level, int maxLevel) const { if (level >= maxLevel) { return node; } if (node->GetChildrenCount() == 0) { return nullptr; } size_t n = node->GetChildrenCount(); for (size_t i = 0; i < n; ++i) { std::shared_ptr<touchmind::model::node::NodeModel> child = node->GetChild(i); std::shared_ptr<touchmind::model::node::NodeModel> leftmostDescendant = GetLeftMost(child, level + 1, maxLevel); if (leftmostDescendant != nullptr) { return leftmostDescendant; } } return nullptr; }