2.2.3.17.32 TreeNode::RemoveChildrenWithPrefix

Description

Removes the node with the specified prefix.

Syntax

int RemoveChildrenWithPrefix( LPCSTR lpcszPrefix = NULL )

Parameters

lpcszPrefix
[input] the prefix of name of the node(s). use NULL or "" to remove all

Return

the number of nodes mathced and was removed successfully; 0 otherwise.

Examples

EX1

// Remove the children with prefix n
void TreeNode_RemoveChildrenWithPrefix_ex1()
{
    Tree myTree;
    TreeNode tn1, tn2;
 
    tn1 = myTree.AddNumericNode(5, "Name", 1);    
    tn2 = myTree.AddNumericNode(6, "Addr", 1);    
    printf("number of nodes = %d \n", myTree.GetNodeCount());        
	//should print 2  
    int flag = myTree.RemoveChildrenWithPrefix("n");
    printf("number of nodes = %d \n", myTree.GetNodeCount());
    //should print 1            
}

EX2

// Use "" to remove all the children
void TreeNode_RemoveChildrenWithPrefix_ex2()
{
    Tree myTree;
    TreeNode tn1, tn2;
 
    tn1 = myTree.AddNumericNode(5, "Name", 1);    
    tn2 = myTree.AddNumericNode(6, "Addr", 1);    
    printf("number of nodes = %d \n", myTree.GetNodeCount());        
	//should print 2
	
    int flag = myTree.RemoveChildrenWithPrefix("");
    printf("number of nodes = %d \n", myTree.GetNodeCount());
    //should print 0            
}

Remark

See Also

TreeNode::RemoveChild

Header to Include

origin.h