當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。