本文整理汇总了C++中GetDepth函数的典型用法代码示例。如果您正苦于以下问题:C++ GetDepth函数的具体用法?C++ GetDepth怎么用?C++ GetDepth使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetDepth函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
main() {
BiTNode * n1 = MakeNode(10, NULL, NULL);
BiTNode * n2 = MakeNode(20, NULL, NULL);
BiTNode * n3 = MakeNode(30, n1, n2);
BiTNode * n4 = MakeNode(40, NULL, NULL);
BiTNode * n5 = MakeNode(50, NULL, NULL);
BiTNode * n6 = MakeNode(60, n4, n5);
BiTNode * n7 = MakeNode(70, NULL, NULL);
BiTree tree = InitBiTree(n7);
SetLChild(tree, n3);
SetRChild(tree, n6);
printf("树的深度为:%d \n", GetDepth(tree));
printTree(tree, GetDepth(tree));
printf("\n先序遍历如下:");
PreOrderTraverse(tree, print);
printf("\n中序遍历如下:");
InOrderTraverse(tree, print);
printf("\n后序遍历如下:");
PostOrderTraverse(tree, print);
DeleteChild(tree, 1);
printf("\n后序遍历如下:");
PostOrderTraverse(tree, print);
DestroyBiTree(tree);
if (IsEmpty(tree))
printf("\n二叉树为空,销毁完毕\n");
}
示例2: GetDepth
void Label::DrawSelf()
{
int l_posX = 0;
int l_posY = 0;
m_pRenderer->SetRenderMode(RM_SOLID);
m_pRenderer->RenderFreeTypeText(m_GUIFont, (float)l_posX, (float)l_posY, GetDepth(), m_colour, 1.0f, "%s", m_text.c_str());
if(m_outline)
{
m_pRenderer->RenderFreeTypeText(m_OutlineGUIFont, (float)l_posX, (float)l_posY, GetDepth(), m_outlineColour, 1.0f, "%s", m_text.c_str());
}
/* DEBUG : Text bounds checking
int l_stringWidth = m_pRenderer->GetFreeTypeTextWidth(m_GUIFont, "%s", m_text.c_str());
int l_stringHeight = m_pRenderer->GetFreeTypeTextHeight(m_GUIFont, "%s", m_text.c_str());
int l_outlineX1 = 0;
int l_outlineX2 = l_stringWidth;
int l_outlineY1 = 0;
int l_outlineY2 = l_stringHeight;
m_pRenderer->PushMatrix();
m_pRenderer->SetRenderMode(RM_WIREFRAME);
m_pRenderer->EnableImmediateMode(IM_QUADS);
m_pRenderer->ImmediateColourAlpha(1.0f, 1.0f, 1.0f, 1.0f);
m_pRenderer->ImmediateVertex(l_outlineX1, l_outlineY1, (int)m_depth);
m_pRenderer->ImmediateVertex(l_outlineX2, l_outlineY1, (int)m_depth);
m_pRenderer->ImmediateVertex(l_outlineX2, l_outlineY2, (int)m_depth);
m_pRenderer->ImmediateVertex(l_outlineX1, l_outlineY2, (int)m_depth);
m_pRenderer->DisableImmediateMode();
m_pRenderer->PopMatrix();
*/
}
示例3: SetPosition
/*--------------------------------------------------------------------------------*/
AudioObjectParameters& AudioObjectParameters::Modify(const Modifier& modifier, const ADMAudioObject *object)
{
if (modifier.rotation.IsSet())
{
SetPosition(GetPosition() * modifier.rotation.Get());
if (IsMinPositionSet()) SetMinPosition(GetMinPosition() * modifier.rotation.Get());
if (IsMaxPositionSet()) SetMaxPosition(GetMaxPosition() * modifier.rotation.Get());
Position size(GetWidth(), GetDepth(), GetHeight());
size *= modifier.rotation.Get();
SetWidth(static_cast<float>(size.pos.x));
SetDepth(static_cast<float>(size.pos.y));
SetHeight(static_cast<float>(size.pos.z));
}
if (modifier.position.IsSet()) SetPosition(GetPosition() + modifier.position.Get());
if (modifier.scale.IsSet())
{
SetPosition(GetPosition() * modifier.scale.Get());
if (IsMinPositionSet()) SetMinPosition(GetMinPosition() * modifier.scale.Get());
if (IsMaxPositionSet()) SetMaxPosition(GetMaxPosition() * modifier.scale.Get());
Position size(GetWidth(), GetDepth(), GetHeight());
size *= modifier.scale.Get();
SetWidth(static_cast<float>(size.pos.x));
SetDepth(static_cast<float>(size.pos.y));
SetHeight(static_cast<float>(size.pos.z));
}
if (modifier.gain.IsSet()) SetGain(GetGain() * modifier.gain.Get());
// apply specific modifications (from derived classes)
modifier.Modify(*this, object);
return *this;
}
示例4: GetDepth
/// 求二叉树的深度
/// 递归解法:如果二叉树为空,二叉树的深度为0
/// 如果二叉树不空,二叉树的深度 = max(左子树深度,右子树深度)+1
int GetDepth(TreeNode* root)
{
if(root == NULL) /// 递归出口
return 0;
int depthLeft = GetDepth(root->left);
int depthRight = GetDepth(root->right);
return (depthLeft > depthRight)?(depthLeft + 1):(depthRight + 1);
}
示例5: while
//更新深度
void MyTree::UpdateDepth(TreeNode* pNode)
{
TreeNode* pParent = pNode->m_pParent;
while(pParent)
{
//设置父节点的深度
int nLeftDepth = GetDepth(pParent->m_pLeft);
int nRightDepth = GetDepth(pParent->m_pRight);
pParent->m_nDepth = max(nLeftDepth, nRightDepth) + 1;
//判断是否平衡
if(abs(nLeftDepth - nRightDepth) >= 2)
{
TreeNode* pNode1 = pParent;
TreeNode* pNode2 = NULL;
TreeNode* pNode3 = NULL;
if(pNode1->m_pLeft)
{
pNode2 = pNode1->m_pLeft;
}
else
{
pNode2 = pNode1->m_pRight;
}
if(pNode2->m_pLeft)
{
pNode3 = pNode2->m_pLeft;
}
else
{
pNode3 = pNode2->m_pRight;
}
//进行相关的旋转操作
if(pNode1->m_pLeft == pNode2 && pNode2->m_pLeft == pNode3)
{
//右单旋
}
else if(pNode1->m_pRight == pNode2 && pNode2->m_pRight == pNode3)
{
//左单旋
}
else if(pNode1->m_pRight == pNode2 && pNode2->m_pLeft == pNode3)
{
//先右单旋 再左单旋
}
else if(pNode1->m_pLeft == pNode2 && pNode2->m_pRight == pNode3)
{
//先左单旋 再右单旋
}
}
pParent = pParent->m_pParent;
}
}
示例6: GetTop
bool
nsTreeRows::iterator::operator==(const iterator& aIterator) const
{
if (GetDepth() != aIterator.GetDepth())
return false;
if (GetDepth() == 0)
return true;
return GetTop() == aIterator.GetTop();
}
示例7: GetTop
bool
nsTreeRows::iterator::operator==(const iterator& aIterator) const
{
if (GetDepth() != aIterator.GetDepth())
return PR_FALSE;
if (GetDepth() == 0)
return PR_TRUE;
return GetTop() == aIterator.GetTop();
}
示例8: wxCHECK_RET
void wxBitmap::SetPalette(const wxPalette& palette)
{
wxCHECK_RET( IsOk(), wxT("invalid bitmap") );
wxCHECK_RET( GetDepth() > 1 && GetDepth() <= 8, wxT("cannot set palette for bitmap of this depth") );
AllocExclusive();
wxDELETE(M_BITMAP->m_palette);
if ( !palette.IsOk() ) return;
M_BITMAP->m_palette = new wxPalette(palette);
}
示例9: GetDepth
///== /////////////////////////////////////////////
int GetDepth(RBTreeNode *node)
{
RBTreeNode *l = node->left;
RBTreeNode *r = node->right;
int ld = 0;
int rd = 0;
if (l != 0) ld = 1 + GetDepth(l);
if (r != 0) rd = 1 + GetDepth(r);
if (ld >= rd) return ld; else return rd;
return 0;
}
示例10:
unsigned int BinarySearchTree<Key, Value>::GetDepth (typename BinarySearchTree<Key, Value>::BSTnode* subtree)
{
unsigned int left=0, right=0, root=0;
if (subtree==NULL)
{
return 0;
}
left=GetDepth(subtree->m_left);
right=GetDepth(subtree->m_right);
root=( left>right ? left : right )+1;
return root;
}
示例11: Parse
void Parse()
{
ReadNextNode();
WriteElement();
int nDepth = GetDepth();
if ( 0 == xmlTextReaderIsEmptyElement(reader) )
{
XmlNodeType eNodeType = XmlNodeType_None;
int nCurDepth = -1;
// У закрывающего тэга глубина на 1 больше, чем у открывающего
while( true )
{
if ( 1 != xmlTextReaderRead(reader) )
break;
int nTempType = xmlTextReaderNodeType(reader);
if(-1 == nTempType)
break;
eNodeType = (XmlNodeType)nTempType;
nCurDepth = GetDepth();
if ( eNodeType == XmlNodeType_Text || eNodeType == XmlNodeType_Whitespace || eNodeType == XmlNodeType_SIGNIFICANT_WHITESPACE )
m_pCurrentNode->m_sText += GetText();
else if (eNodeType == XmlNodeType_Element)
WriteElement();
else if (eNodeType == XmlNodeType_EndElement)
{
m_list.pop_back();
if (0 != m_list.size())
{
std::list<CXmlNodeBase*>::iterator iter = m_list.end();
--iter;
m_pCurrentNode = *iter;
}
else
{
m_pCurrentNode = m_pNode;
}
}
nCurDepth = GetDepth();
if ( nCurDepth < nDepth )
break;
if ( XmlNodeType_EndElement == eNodeType && nCurDepth == nDepth )
break;
}
}
}
示例12: NS_PRECONDITION
void
nsTreeRows::iterator::Prev()
{
NS_PRECONDITION(GetDepth() > 0, "cannot increment an uninitialized iterator");
// Decrement the absolute row index
--mRowIndex;
// Move to the previous child in this subtree
--(GetTop().mChildIndex);
// Have we exhausted the current subtree?
if (GetTop().mChildIndex < 0) {
// Yep. See if we've just iterated back to the first element
// in the tree, period. Walk back up the stack, looking for
// any unfinished subtrees.
PRInt32 unfinished;
for (unfinished = GetDepth() - 2; unfinished >= 0; --unfinished) {
const Link& link = mLink[unfinished];
if (link.mChildIndex >= 0)
break;
}
// If there are no unfinished subtrees in the stack, then this
// iterator is exhausted. Leave it in the same state that
// First() does.
if (unfinished < 0)
return;
// Otherwise, we ran off the end of one of the inner
// subtrees. Pop up to the next unfinished level in the stack.
mLink.SetLength(unfinished + 1);
return;
}
// Is there a child subtree immediately prior to our current
// position? If so, descend into it, grovelling down to the
// deepest, rightmost left edge.
Subtree* parent = GetTop().GetParent();
PRInt32 index = GetTop().GetChildIndex();
Subtree* subtree = (*parent)[index].mSubtree;
if (subtree && subtree->Count()) {
do {
index = subtree->Count() - 1;
Append(subtree, index);
parent = subtree;
subtree = (*parent)[index].mSubtree;
} while (subtree && subtree->Count());
}
}
示例13: CheckList
void ExperimentalPoint::CheckList(TString grid, int quad, int level){
//Check if it's already in the list
for (unsigned i = 0 ; i < flistGrid.size() ; i++)
if(grid == flistGrid.at(i) && quad == flistQuad.at(i) && GetDepth(level) == flistDepth.at(i) ) return ;
//otherwise
flistGrid.push_back(grid) ;
flistQuad.push_back(quad) ;
flistDepth.push_back(GetDepth(level));
return;
}
示例14: GetDepth
//函数返回根结点的最大和最小深度
Depth GetDepth(SearchTree tree) {
if (NULL == tree) {
Depth empty = {0, 0};
return empty;
}
Depth lhs = GetDepth(tree->left);
Depth rhs = GetDepth(tree->right);
Depth depth;
depth.max_depth = 1 + max(lhs.max_depth, rhs.max_depth);
depth.min_depth = 1 + min(lhs.min_depth, rhs.min_depth);
return depth;
}
示例15: GetDepth
//求二叉树深度
int GetDepth( BiNode *T )
{
if( T == NULL )
{
return 0;
}
// int Left_Length = GetDepth( T->lch );
// int Right_Length = GetDepth( T->rch );
// return Left_length > Right_Length ?( Left_Length + 1 ) : ( Right_length + 1 );
return GetDepth( T->lch ) > GetDepth( T->rch ) ?
( GetDepth( T->lch ) + 1 ) : ( GetDepth( T->rch ) + 1 );
}