本文整理汇总了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;
}
}