当前位置: 首页>>代码示例>>C++>>正文


C++ DestroyTree函数代码示例

本文整理汇总了C++中DestroyTree函数的典型用法代码示例。如果您正苦于以下问题:C++ DestroyTree函数的具体用法?C++ DestroyTree怎么用?C++ DestroyTree使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了DestroyTree函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Test2

// There are branches in trees, and tree B is not a subtree of tree A
//                  8                8
//              /       \           / \
//             8         7         9   2
//           /   \
//          9     3
//               / \
//              4   7
void Test2()
{
    BinaryTreeNode* pNodeA1 = CreateBinaryTreeNode(8);
    BinaryTreeNode* pNodeA2 = CreateBinaryTreeNode(8);
    BinaryTreeNode* pNodeA3 = CreateBinaryTreeNode(7);
    BinaryTreeNode* pNodeA4 = CreateBinaryTreeNode(9);
    BinaryTreeNode* pNodeA5 = CreateBinaryTreeNode(3);
    BinaryTreeNode* pNodeA6 = CreateBinaryTreeNode(4);
    BinaryTreeNode* pNodeA7 = CreateBinaryTreeNode(7);

    ConnectTreeNodes(pNodeA1, pNodeA2, pNodeA3);
    ConnectTreeNodes(pNodeA2, pNodeA4, pNodeA5);
    ConnectTreeNodes(pNodeA5, pNodeA6, pNodeA7);

    BinaryTreeNode* pNodeB1 = CreateBinaryTreeNode(8);
    BinaryTreeNode* pNodeB2 = CreateBinaryTreeNode(9);
    BinaryTreeNode* pNodeB3 = CreateBinaryTreeNode(2);

    ConnectTreeNodes(pNodeB1, pNodeB2, pNodeB3);

    Test("Test2", pNodeA1, pNodeB1, false);

    DestroyTree(pNodeA1);
    DestroyTree(pNodeB1);
}
开发者ID:brian-smith723,项目名称:DesignPatterns,代码行数:33,代码来源:050_SubtreeInTree.cpp

示例2: main

int main(void) {
	unsigned char pkt[200];
	req r;
	ssize_t len;
	unsigned int i;
	FILE *in;
	uint32_t seed;

	signal(SIGALRM, tooslow);
	alarm(TIMEOUT);

	// set up the head of the SNMP MIB tree
	InitTree();
	SetCount = 0;
	ErrCount = 0;

	// seed the prng
	if ((in = fopen("/dev/urandom", "r")) == NULL) {
		exit(-1);
	}
	if (fread(&seed, 1, 4, in) != 4) {
		exit(-1);
	}
	fclose(in);
	srand(seed);

	// init the MIB with some objects
	PopulateMIB();

	while (1) {
		if (ErrCount > MAX_ERRORS) {
			DestroyTree(MIB);
			exit(-1);
		}
		bzero(pkt, 200);
		bzero(&r, sizeof(req));

		if ((len = ReceivePacket(pkt, 200)) == 0) {
			DestroyTree(MIB);
			exit(-1);
		}

		// reset the timer
		alarm(TIMEOUT);
		
		// parse the packet and handle the particular request
		if (ParseSnmpPkt(pkt, len, &r)) {
			if (r.type == GET_REQUEST) {
				HandleGetRequest(&r);
			} else if (r.type == GET_NEXT_REQUEST) {
				HandleGetNextRequest(&r);
			} else if (r.type == SET_REQUEST) {
				HandleSetRequest(&r);
			}
		} else {
			// error parsing packet
			ErrCount++;
		}
	}
}
开发者ID:legitbs,项目名称:quals-2015,代码行数:60,代码来源:snmpv1.c

示例3: Test6

// Nodes in tree A only have right children, and tree B is not a subtree of tree A
//       8                   8
//        \                   \ 
//         8                   9   
//          \                 / \
//           9               3   2
//            \      
//             2        
//              \
//               5
void Test6()
{
    BinaryTreeNode* pNodeA1 = CreateBinaryTreeNode(8);
    BinaryTreeNode* pNodeA2 = CreateBinaryTreeNode(8);
    BinaryTreeNode* pNodeA3 = CreateBinaryTreeNode(9);
    BinaryTreeNode* pNodeA4 = CreateBinaryTreeNode(2);
    BinaryTreeNode* pNodeA5 = CreateBinaryTreeNode(5);

    ConnectTreeNodes(pNodeA1, NULL, pNodeA2);
    ConnectTreeNodes(pNodeA2, NULL, pNodeA3);
    ConnectTreeNodes(pNodeA3, NULL, pNodeA4);
    ConnectTreeNodes(pNodeA4, NULL, pNodeA5);

    BinaryTreeNode* pNodeB1 = CreateBinaryTreeNode(8);
    BinaryTreeNode* pNodeB2 = CreateBinaryTreeNode(9);
    BinaryTreeNode* pNodeB3 = CreateBinaryTreeNode(3);
    BinaryTreeNode* pNodeB4 = CreateBinaryTreeNode(2);

    ConnectTreeNodes(pNodeB1, NULL, pNodeB2);
    ConnectTreeNodes(pNodeB2, pNodeB3, pNodeB4);

    Test("Test6", pNodeA1, pNodeB1, false);

    DestroyTree(pNodeA1);
    DestroyTree(pNodeB1);
}
开发者ID:brian-smith723,项目名称:DesignPatterns,代码行数:36,代码来源:050_SubtreeInTree.cpp

示例4: DeleteChild

Status DeleteChild(CSTree &T, CSTree p, int i)
{
	CSTree b, q;
	int j;

	if (T) {
		if (i == 1) {
			b = p->firstchild;
			p->firstchild = b->nextsibling;
			b->nextsibling = NULL;
			DestroyTree(b);
		} else { q = p->firstchild;
			 j = 2;
			 while (q && j < i) {
				 q = q->nextsibling;
				 j++;
			 }
			 if (j == i) {
				 b = q->nextsibling;
				 q->nextsibling = b->nextsibling;
				 b->nextsibling = NULL;
				 DestroyTree(b);
			 } else {
				 return ERROR;
			 } }
		return OK;
	} else {
		return ERROR;
	}
}
开发者ID:zqw86713,项目名称:Data.Structure.Solution,代码行数:30,代码来源:bo6-5.cpp

示例5: Test3

// Nodes in trees only have left children, and tree B is a subtree of tree A
//                8                  8
//              /                   / 
//             8                   9   
//           /                    /
//          9                    2
//         /      
//        2        
//       /
//      5
void Test3()
{
    BinaryTreeNode* pNodeA1 = CreateBinaryTreeNode(8);
    BinaryTreeNode* pNodeA2 = CreateBinaryTreeNode(8);
    BinaryTreeNode* pNodeA3 = CreateBinaryTreeNode(9);
    BinaryTreeNode* pNodeA4 = CreateBinaryTreeNode(2);
    BinaryTreeNode* pNodeA5 = CreateBinaryTreeNode(5);

    ConnectTreeNodes(pNodeA1, pNodeA2, NULL);
    ConnectTreeNodes(pNodeA2, pNodeA3, NULL);
    ConnectTreeNodes(pNodeA3, pNodeA4, NULL);
    ConnectTreeNodes(pNodeA4, pNodeA5, NULL);

    BinaryTreeNode* pNodeB1 = CreateBinaryTreeNode(8);
    BinaryTreeNode* pNodeB2 = CreateBinaryTreeNode(9);
    BinaryTreeNode* pNodeB3 = CreateBinaryTreeNode(2);

    ConnectTreeNodes(pNodeB1, pNodeB2, NULL);
    ConnectTreeNodes(pNodeB2, pNodeB3, NULL);

    Test("Test3", pNodeA1, pNodeB1, true);

    DestroyTree(pNodeA1);
    DestroyTree(pNodeB1);
}
开发者ID:brian-smith723,项目名称:DesignPatterns,代码行数:35,代码来源:050_SubtreeInTree.cpp

示例6: DestroyTree

/**
 * 删除一棵树,并释放相应的结点空间
 * 注意,不要忘了加&,否则T无法释放
 */
void DestroyTree(BiTree &T)
{
	if (T) {
		DestroyTree(T->lchild);	//先删除左右子树
		DestroyTree(T->rchild);
		free(T);
		T = NULL;
	}
}
开发者ID:Annie2333,项目名称:DS_Code,代码行数:13,代码来源:practice.cpp

示例7: DestroyTree

void DestroyTree(CSTree &T)
{
	if (T) {
		DestroyTree(T->firstchild);
		DestroyTree(T->nextsibling);
		free(T);
		T = NULL;
	}
}
开发者ID:zqw86713,项目名称:Data.Structure.Solution,代码行数:9,代码来源:bo6-5.cpp

示例8: DestroyTree

void BinaryTree::DestroyTree ( node* leaf )
{
	if ( leaf != NULL )
	{
		DestroyTree ( leaf->left );
		DestroyTree ( leaf->right );
		delete leaf;
	}
}
开发者ID:MiloshHasCamo,项目名称:Motor,代码行数:9,代码来源:BinaryTree.cpp

示例9: DestroyTree

static void
DestroyTree( BinTree T )
{
    if( T != NULL )
    {
        DestroyTree( T->LeftChild );
        DestroyTree( T->NextSibling );
        free( T );
    }
}
开发者ID:adofsauron,项目名称:vsproj,代码行数:10,代码来源:binomial.c

示例10: DestroyTree

/* This frees the memory for a binary tree of type LEAF* using recursion
   the parameter is the head of the tree. 
*/
void DestroyTree(LEAF* head) {
   if (head == NULL) {
      return;
   }
   else {
      DestroyTree(head->lchild);
      DestroyTree(head->rchild);
      free(head);
   }
}
开发者ID:LukeWalsh,项目名称:ipa2_1,代码行数:13,代码来源:utility.c

示例11: DestroyTree

void DestroyTree(BSTreeNode* root)
{
	if(root)
	{
		DestroyTree(root->m_pLeft);
		DestroyTree(root->m_pRight);
		delete root;
		root = 0;
	}
}
开发者ID:MarsZhuJin,项目名称:microsoft-interview-100,代码行数:10,代码来源:weiruan_1.cpp

示例12: DestroyTree

void BinarySearchTree::DestroyTree( Node *node )
{
	if ( node != nullptr )
	{
		DestroyTree( node->left );
		DestroyTree( node->right );

		delete node;
		node = nullptr;
	}
}
开发者ID:zrma,项目名称:AlgorithmAdvanced,代码行数:11,代码来源:BinarySearchTree.cpp

示例13: DestroyTree

// Release the resources
void BinaryTreeMethod::DestroyTree(TreeNode **p_Root)
{
	if(!p_Root || !(*p_Root))
	{
		return;
	}
	DestroyTree(&((*p_Root)->p_left));
	DestroyTree(&((*p_Root)->p_right));
	delete *p_Root;
	p_Root = 0;
}
开发者ID:jiabailie,项目名称:Algorithm,代码行数:12,代码来源:BinaryTree.cpp

示例14: DestroyTree

 void DestroyTree(CSTree *T)
 { /* 初始条件: 树T存在。操作结果: 销毁树T */
   if(*T)
   {
     if((*T)->firstchild) /* T有长子 */
       DestroyTree(&(*T)->firstchild); /* 销毁T的长子为根结点的子树 */
     if((*T)->nextsibling) /* T有下一个兄弟 */
       DestroyTree(&(*T)->nextsibling); /* 销毁T的下一个兄弟为根结点的子树 */
     free(*T); /* 释放根结点 */
     *T=NULL;
   }
 }
开发者ID:githubzenganiu,项目名称:toekn,代码行数:12,代码来源:1-71.c

示例15: DestroyTree

 static void DestroyTree(CSTree &T)
 { // 初始条件: 树T存在。操作结果: 销毁树T
   if(T)
   {
     if(T->firstchild) // T有长子
       DestroyTree(T->firstchild); // 销毁T的长子为根结点的子树
     if(T->nextsibling) // T有下一个兄弟
       DestroyTree(T->nextsibling); // 销毁T的下一个兄弟为根结点的子树
     free(T); // 释放根结点
     T=NULL;
   }
 }
开发者ID:cjpthree,项目名称:datastructure_vs,代码行数:12,代码来源:Bo6-5.cpp


注:本文中的DestroyTree函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。