AVLTree rightLeftRotate(AVLTree tree){ AVLTree k1 = tree->right; AVLTree k2 = k1->left; k2->parent = tree->parent; tree->right = k2->left; if(k2->left) k2->left->parent = tree; k1->left = k2->right; if(k2->right) k2->right->parent = k1; k2->left = tree; tree->parent = k2; k2->right = k1; k1->parent = k2; tree->height = getChildMaxHeight(tree)+1; k1->height = getChildMaxHeight(k1)+1; k2->height = getChildMaxHeight(k2); return k2; }
AVLTree rightRotate(AVLTree tree) { AVLTree newParent = tree->left; newParent->parent = tree->parent; tree->parent = newParent; tree->left = newParent->right; if(newParent->right) newParent->right->parent = tree; newParent->right = tree; tree->height = getChildMaxHeight(tree)+1; newParent->height = getChildMaxHeight(newParent)+1; return newParent; }
void adjustTreeHeight(AVLTree tree) { while (tree){ tree->height = getChildMaxHeight(tree)+1; tree = tree->parent; } }
void connectParentAndSon(AVLTree parentNode, AVLTree sonNode, long leftOrRight){ if (leftOrRight == -1) { return; } if (parentNode) { if(leftOrRight == 0){ parentNode->left = sonNode; }else{ parentNode->right = sonNode; } sonNode->parent = parentNode; parentNode->height = getChildMaxHeight(parentNode)+1; } }
void CUITree::addTree( CUITree* pTree, bool bAddBtn ) { if (pTree == NULL) return; // 기본 아이디 지정 char buf[64]; int idx = m_vecTree.size(); sprintf(buf, "tree_item_%03d", idx + 1); pTree->setID(buf); pTree->setControlIndex(idx); m_vecTree.push_back(pTree); addChild(pTree); CUICheckButton* pCheck = pTree->getCheck(); if (bAddBtn == true && pCheck != NULL) { { int x, y; pCheck->GetPos(x, y); int h = getChildMaxHeight(); h -= pCheck->GetHeight(); if (h > 0) { y = y + (h / 2); pCheck->SetPos(x, y); } } pTree->addChild(pCheck); pTree->setAddCheck(true); CmdUncollapse* pCmd = new CmdUncollapse; pCmd->setData(pTree); pCheck->SetCommand(pCmd); } }
void CUITree::onUpdateTree(CUIScrollBar* pScroll) { int i, nMax; CUITree* pItem; int x = 0; int accumY = 0; int nStart = 0; int startY = getParentoffset(); int offY = getChildMaxHeight(); int nScrollStart = 0; int nScrollEnd = 0; if (pScroll != NULL) { nScrollStart = pScroll->GetScrollPos(); nScrollEnd = nScrollStart + pScroll->GetItemsPerPage(); } nMax = m_vecTree.size(); for (i = 0; i < nMax; ++i) { pItem = (CUITree*)m_vecTree[i]; if (pItem == NULL) continue; int nIdx = pItem->getTreeIndex(); // Scroll 영역에 들어왔는지 검사 // 부모의 형제 위치를 계산해야 하므로 Hide 라도 건너뛰면 안된다. if (pScroll != NULL && (nIdx < nScrollStart || nIdx >= nScrollEnd)) { pItem->Hide(TRUE); if (pItem->getCheck() != NULL) pItem->getCheck()->Hide(TRUE); } else { pItem->Hide(FALSE); if (pItem->getCheck() != NULL) pItem->getCheck()->Hide(FALSE); } //if (GetHide() == FALSE && getRoot() == false) if (getRoot() == false) accumY = (i + 1) * (pItem->getTreeItemHeight() + m_nGap); else accumY = (nIdx - nScrollStart) * (pItem->getTreeItemHeight() + m_nGap); x = pItem->GetPosX(); pItem->SetPos(x, accumY); } m_nSumHeight = accumY; if (m_bRoot == false) { if (getUncollapse() == FALSE) { SetHeight(offY); } else { SetHeight(offY + m_nSumHeight); } } updateTreeChild(pScroll); }