本文整理汇总了C++中destroyTree函数的典型用法代码示例。如果您正苦于以下问题:C++ destroyTree函数的具体用法?C++ destroyTree怎么用?C++ destroyTree使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了destroyTree函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: destroyTree
void exprTree::destroyTree(Node *leaf) {
if (leaf != nullptr) {
destroyTree(leaf->left);
destroyTree(leaf->right);
delete leaf;
}
}
示例2: so
/*prints all the files associated with any word*/
int so(char *str, hashTable *ht) {
char *word;
FileNode *fptr; /* Iterates through filenames */
if (strcmp(strtok(str, " "), "so") != 0) {
printf("I did not get 'so' inside sa function!!\n");
return 1;
}
/* goes through each word in input */
while ((word = strtok(NULL, " "))) {
for (ptr = getFiles(word, root); ptr != NULL;
ptr = ptr->next) {
insert_to_list(t, ptr->filename);
}
}
/* Means we got no matches */
if (t->files == NULL) {
printf("No matches found.\n");
destroyTree(t);
return 1;
}
/* prints all the filenames */
for (ptr = t->files; ptr->next != NULL; ptr = ptr->next)
printf("%s, ", ptr->filename);
if (ptr)
printf("%s\n", ptr->filename);
destroyTree(t);
return 0;
}
示例3: destroyTree
void Node::destroyTree(Node *a) {
if (a != NULL)
{
destroyTree(a->left);
destroyTree(a->right);
delete a;
}
};
示例4: destroyTree
void destroyTree(node *in){
if(in != 0){
destroyTree(in->left);
destroyTree(in->right);
free(in);
}
}
示例5: destroyTree
void destroyTree(struct tree* victim){
if(victim->son1)
destroyTree(victim->son1);
if(victim->son2)
destroyTree(victim->son2);
free(victim);
victim = 0;
}
示例6: destroyTree
void destroyTree(NodePtr leaf) {
if(leaf != nullptr) {
destroyTree(leaf->left);
destroyTree(leaf->right);
delete leaf;
--numberOfNodes;
}
}
示例7: bipartGraphDestroy
void bipartGraphDestroy(bpGraph_t* pGraph)
{
/* TODO: Implement me! */
destroyTree(pGraph->vpVertsP1);
destroyTree(pGraph->vpVertsP2);
safeFree(pGraph, sizeof(bpGraph_t));
pGraph = NULL;
} /* end of bipartGraphDestroy() */
示例8: destroyTree
//--------------------------------------------------------------------------
// void destroyTree(BSTNode* subTreePtr);
// Taken from Carrano et al.: method used to destruct a BST
// Preconditions: BST exists
// Postconditions: BST is destructed
// Return value: None
// Functions called: Recursive call to itself
void BST::destroyTree(BSTNode* subTreePtr) {
if (subTreePtr != nullptr)
{
destroyTree(subTreePtr->left);
destroyTree(subTreePtr->right);
delete subTreePtr;
}
}
示例9: destroyTree
void destroyTree(HuffNode * tree)
/*This function deallocates the memory allocated by the Huffman tree.*/
{
if(tree == NULL){return;}//base case:reach the leaf of the tree, return to free the leaf
destroyTree(tree -> left);//check all the left children
destroyTree(tree -> right);//check all the right children
free(tree);//free the memory of the tree
}
示例10: destroyTree
//Deallocates memory for the given root and all its subtrees
//O(h)
void destroyTree(struct tree *root){
//Since this is a tree, we can use post order recursion to recusrivley delete all the nodes in the left and right subtree then the root
if(root!=NULL){
destroyTree(root->left);
destroyTree(root->right);
free(root);
}
}
示例11: destroyTree
// Private destroyTree function. It will delete all the nodes of the tree
void BinaryTree::destroyTree(TreeNode *leaf)
{
if(leaf!=NULL)
{
destroyTree(leaf->left);
destroyTree(leaf->right);
delete leaf;
}
}
示例12: bipartGraphDestroy
void bipartGraphDestroy(bpGraph_t* pGraph)
{
/* Destroy each partite tree */
destroyTree(*pGraph->vertices1);
destroyTree(*pGraph->vertices2);
/* Free the graph struct */
safeFree(pGraph, sizeof(pGraph));
} /* end of bipartGraphDestroy() */
示例13: destroyTree
void LinkedBinaryTree<T>::destroyTree(Node* p) {
if (p != NULL) {
destroyTree(p->left);
destroyTree(p->right);
delete p;
}
}
示例14: destroyTree
void BinaryNodeTree<ItemType>::destroyTree(BinaryNode<ItemType>* subTreePtr)
{
if (subTreePtr != nullptr)
{
destroyTree(subTreePtr->getLeftChildPtr());
destroyTree(subTreePtr->getRightChildPtr());
delete subTreePtr;
} // end if
} // end destroyTree
示例15: destroyTree
void BST::destroyTree(TreeNode *& treePtr)
{
// postorder traversal
if (treePtr != NULL)
{ destroyTree(treePtr->leftChildPtr);
destroyTree(treePtr->rightChildPtr);
delete treePtr;
treePtr = NULL;
} // end if
} // end destroyTree