Esempio n. 1
0
void exprTree::destroyTree(Node *leaf) {
	if (leaf != nullptr) {
		destroyTree(leaf->left);
		destroyTree(leaf->right);
		delete leaf;
	}
}
Esempio n. 2
0
/*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;
}
Esempio n. 3
0
File: L4.cpp Progetto: Themiak/SDiZO
void Node::destroyTree(Node *a) {
	if (a != NULL)
	{
		destroyTree(a->left);
		destroyTree(a->right);
		delete a;
	}
};
void destroyTree(node *in){

  if(in != 0){
    destroyTree(in->left);
    destroyTree(in->right);
    free(in);
  }
}
Esempio n. 5
0
void destroyTree(struct tree* victim){
    if(victim->son1)
       destroyTree(victim->son1);
    if(victim->son2)
       destroyTree(victim->son2);
    free(victim);
    victim = 0; 
}
Esempio n. 6
0
 void destroyTree(NodePtr leaf) {
   if(leaf != nullptr) {
     destroyTree(leaf->left);
     destroyTree(leaf->right);
     delete leaf;
     --numberOfNodes;
   }
 } 
Esempio n. 7
0
void bipartGraphDestroy(bpGraph_t* pGraph)
{
	/* TODO: Implement me! */
	destroyTree(pGraph->vpVertsP1);
	destroyTree(pGraph->vpVertsP2);
	safeFree(pGraph, sizeof(bpGraph_t));
	pGraph = NULL;
} /* end of bipartGraphDestroy() */
Esempio n. 8
0
//--------------------------------------------------------------------------
// 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;
   }
} 
Esempio n. 9
0
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
}
Esempio n. 10
0
//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);
	}
}
// 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;
	}
}
Esempio n. 12
0
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() */
void LinkedBinaryTree<T>::destroyTree(Node* p) {
  
  if (p != NULL) {
    destroyTree(p->left);
    destroyTree(p->right);
    delete p;
  }
  
}
Esempio n. 14
0
void BinaryNodeTree<ItemType>::destroyTree(BinaryNode<ItemType>* subTreePtr)
{
   if (subTreePtr != nullptr)
   {
      destroyTree(subTreePtr->getLeftChildPtr());
      destroyTree(subTreePtr->getRightChildPtr());
      delete subTreePtr;
   }  // end if
}  // end destroyTree
Esempio n. 15
0
void BST::destroyTree(TreeNode *& treePtr)
{
   // postorder traversal
   if (treePtr != NULL)
   {  destroyTree(treePtr->leftChildPtr);
      destroyTree(treePtr->rightChildPtr);
      delete treePtr;
      treePtr = NULL;
   }  // end if
}  // end destroyTree
Esempio n. 16
0
void destroyTree(TreeNode * tn)
{
  if (tn == NULL)
    {
      return;
    }
  destroyTree(tn -> left);
  destroyTree(tn -> right);
  free(tn);
}
void destroyTree(node_t* root)
{
	//free all node
	if (root)
	{
		destroyTree(root->left);
		destroyTree(root->right);
		free(root);
	}
}
void destroyTree(BinaryTreeNode* root)
{
	if(root)
	{
		destroyTree(root->m_pLeft);
		destroyTree(root->m_pRight);
		delete root;
		root = 0;
	}
}
Esempio n. 19
0
void bipartGraphDestroy(bpGraph_t* pGraph)
{
   /* this function checks for NULL */
   destroyTree(pGraph->adjTreeP1);
   destroyTree(pGraph->adjTreeP2);

   safeFree(pGraph->vertExistsP1, pGraph->numVertsP1 * sizeof(char));
   safeFree(pGraph->vertExistsP2, pGraph->numVertsP2 * sizeof(char));

   safeFree(pGraph, sizeof(bpGraph_t));
} /* end of bipartGraphDestroy() */
Esempio n. 20
0
//----------------------------------------------------------------------------
// DestroyTree
// postorder deletion of nodes in the tree
// @param tree current node passed into recursive function
//
void BinTree::destroyTree(Node*& tree){
	if (tree != NULL){
		destroyTree(tree->left); //destroy left
		destroyTree(tree->right); //destroy right

		delete tree->movie; //delete NodeData
		tree->movie = NULL;
		delete tree; //Delete Node
		tree = NULL;
	}
} //end destroyTree
Esempio n. 21
0
void BinaryTree::destroyTree(BinaryNode* nodePtr)
{
    // left-root-right
    if (nodePtr == 0)
    {
        return;
    }
    destroyTree(nodePtr->getLeftPtr());
    destroyTree(nodePtr->getRightPtr());
    delete nodePtr;
}
//!-----------------------------------------
void destroyTree(treeElem_t *root)
{
    assert(root);

    if (root->left)
        destroyTree(root->left);
    if (root->right)
        destroyTree(root->right);

    dtor(root);
}
Esempio n. 23
0
//----------------------------------------------------------------------------
// destroyTree
// Uses a postorder traversal to destroy BST
void BinTree::destroyTree(Node*& nodePtr)
{
    if (nodePtr != NULL)
    {
        destroyTree(nodePtr->left); // destroy left child
        destroyTree(nodePtr->right); // destroy right child
        delete nodePtr->data; // delete NodeData
        nodePtr->data = NULL;
        delete nodePtr; // Delete Node
        nodePtr = NULL;
    }
}
Esempio n. 24
0
/**
* CABT::destroyTree
* @date Modified Apr 17, 2006
*/
void CABT::destroyTree(SABTNode* pNode)
{
	ACEASSERT(pNode);

	// Save subtrees
	SABTNode* pLeft = pNode->m_pLeft, *pRight = pNode->m_pRight;

	// Deallocate node
	COM_RELEASE(pNode->m_pVB);
	delete pNode;

	// Continue down the tree.
	if(pLeft) destroyTree(pLeft);
	if(pRight) destroyTree(pRight);
}
Esempio n. 25
0
/*
 * Destroy a tree.
 */
void destroyTree(binTreeNode_t *pTree)
{
	binTreeNode_t *pLeftChild = pTree->left, *pRightChild = pTree->right;

	if (pLeftChild != NULL) {
		destroyTree(pLeftChild);
	}

	if (pRightChild != NULL) {
		destroyTree(pRightChild);
	}

	destroyTreeNode(pTree);
	pTree = NULL;
} /* end of destroyTree() */
Esempio n. 26
0
int main(int argc, char **argv) {
  FILE *rf; /* read file */
  tnode trie;

  /* Check if file exists */
  if (access(argv[1], F_OK) == -1) {
    printf("Input file does not exist\n");
    return 1;
  }

  rf = fopen(argv[1], "r");
  if (!fileIsValid(rf)) {
    return 1;
  }

  trie = createTree();
  loadFileToTree(trie, rf);


  /* Start menu loop */
  menu();

  doSearchLoop(trie);


  fclose(rf);
  destroyTree(trie);
  destroy_list(FILES);

  return 0;
}
Esempio n. 27
0
File: 6.cpp Progetto: dasima/Books
void constructTreeTest(int *pre_order, 
        int *in_order, 
        int length)
{
    std::cout << "---The pre order sequence is:---\n";
    for(int index = 0; index < length; ++index)
        std::cout << pre_order[index];
    std::cout << std::endl;

    std::cout << "---The in_order sequence is:---\n";
    for(int index = 0; index < length; ++index)
        std::cout << in_order[index];
    std::cout << std::endl;

    try
    {
        BinaryTreeNode *root = constructTree(pre_order, 
                in_order, 
                length);
        printTree(root);

        destroyTree(root);
    }
    catch(std::exception &exception)
    {
        std::cout << "Invalid inout.\n";
    }
}
void mode2 (FILE *in, FILE *out) {
	int ln = 0, pn = 0;
	
	TLine *lines = getLines(in, &ln);		
	
	//build tree using lines
	Tree T = buildTree(lines, ln);
	
	free(lines);
	lines = NULL;
	
	//reads points after building tree (better memory usage)
	TPoint *points = getPoints(in, &pn);
	
	labelRegions(T, points, pn);
	
	free(points);
	points = NULL;
	
	printTree(out, T);
	fprintf(out, "\n");
	
	localizePoints(in, out, T);
	
	destroyTree(&T);
}
void mode1 (FILE *in, FILE *out) {
	//line number and point number
	int ln = 0, pn = 0;
	
	//get lines 
	TLine *lines = getLines(in, &ln);
	
	//get points
	TPoint *points = getPoints(in, &pn);
	
	//read tree from file
	Tree T = readTree(in, lines);
	
	//need lines no longer
	free(lines);
	lines = NULL;
	
	//label regions using points
	labelRegions(T, points, pn);
	
	//need points no longer
	free(points);
	points = NULL;
	
	//print tree
	printTree(out, T);
	fprintf(out, "\n");
	
	//solve all points 
	localizePoints(in, out, T);
	
	destroyTree(&T);
}
Esempio n. 30
0
void destroyTree( tree_node * node ) {
	if ( node->left_child == NULL && node->right_child == NULL ) {
		free(node->numericVal);
		free(node->string_val);
		free(node->value);
		free(node);
	} else {
		destroyTree( node->left_child );
		destroyTree( node->right_child );

		free(node->numericVal);
		free(node->string_val);
		free(node->value);
		free(node);
	}
}