本文整理匯總了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);
}
示例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++;
}
}
}
示例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);
}
示例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;
}
}
示例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);
}
示例6: DestroyTree
/**
* 刪除一棵樹,並釋放相應的結點空間
* 注意,不要忘了加&,否則T無法釋放
*/
void DestroyTree(BiTree &T)
{
if (T) {
DestroyTree(T->lchild); //先刪除左右子樹
DestroyTree(T->rchild);
free(T);
T = NULL;
}
}
示例7: DestroyTree
void DestroyTree(CSTree &T)
{
if (T) {
DestroyTree(T->firstchild);
DestroyTree(T->nextsibling);
free(T);
T = NULL;
}
}
示例8: DestroyTree
void BinaryTree::DestroyTree ( node* leaf )
{
if ( leaf != NULL )
{
DestroyTree ( leaf->left );
DestroyTree ( leaf->right );
delete leaf;
}
}
示例9: DestroyTree
static void
DestroyTree( BinTree T )
{
if( T != NULL )
{
DestroyTree( T->LeftChild );
DestroyTree( T->NextSibling );
free( T );
}
}
示例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);
}
}
示例11: DestroyTree
void DestroyTree(BSTreeNode* root)
{
if(root)
{
DestroyTree(root->m_pLeft);
DestroyTree(root->m_pRight);
delete root;
root = 0;
}
}
示例12: DestroyTree
void BinarySearchTree::DestroyTree( Node *node )
{
if ( node != nullptr )
{
DestroyTree( node->left );
DestroyTree( node->right );
delete node;
node = nullptr;
}
}
示例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;
}
示例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;
}
}
示例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;
}
}