Ejemplo n.º 1
0
/******************************
removeFromTree

This function removes a data item from the tree and adjusts the remaining 
branches of the tree to keep the tree in the proper order

****************************/
Tree* removeFromTree(Tree ** root, TreeDataTypePtr data)
{
  int ret;
  Tree* TmpCell = NULL;
  if (*root)
  {
    ret = (*m_comparePointer)(data, (*root)->content);
    if (ret < 0)
      (*root)->left = removeFromTree(&(*root)->left, data);
    else if (ret > 0)
      (*root)->right = removeFromTree(&(*root)->right, data);
    else
    {
      if ((*root)->left && (*root)->right ) {
        TmpCell = FindMin((*root)->right); 
        strncpy((*root)->content, TmpCell->content, strlen(TmpCell->content)+1);
        (*root)->right = removeFromTree(&(*root)->right, (*root)->content);
      } else {
        TmpCell = (*root);
        if ((*root)->left == NULL )
          (*root) = (*root)->right;
        else if ((*root)->right == NULL )
          (*root) = (*root)->left;
        free(TmpCell);
      }
    }
  }
  return *root;
} 
Ejemplo n.º 2
0
/* Entfernt einen Knoten aus einem Baum
 */
void removeFromTree(node * myNode, node ** tree)
{
	if (myNode == 0) { puts("ERROR! Node to remove is NULL!"); return;}
	if (*tree == 0) { puts("ERROR! Node to remove not found!"); return;}
	if (myNode == *tree)
	{
		/* myNode ist Wurzel von Baum.
		 * Nehme rechten Knoten als neue Root
		 * oder linken Knoten, wenn rechter = 0
		 */
		if (myNode->right != 0)
		{
			*tree = myNode->right;
			if (myNode->left != 0)
				insertToTree(myNode->left, tree);
		}
		else
			*tree = myNode->left; /* Darf 0 sein */
		myNode->left = 0;
		myNode->right = 0;
	}
	else if (myNode > *tree)
		removeFromTree(myNode, &((*tree)->right));
	else
		removeFromTree(myNode, &((*tree)->left));
}
Ejemplo n.º 3
0
void
HTTP2PriorityQueue::Node::dropPriorityNodes() {
  for (auto it = children_.begin(); it != children_.end(); ) {
    auto& child = *it++;
    child->dropPriorityNodes();
  }
  if (!txn_ && !isPermanent_) {
    removeFromTree();
  }
}
Ejemplo n.º 4
0
int main()
{
	Tree * testTree;
	int (*compare)(void *, void *, void*, void*);
    void (*destroy)(void *);
    compare = &comparePointer;
    destroy = &destroyPointer;
	testTree = createAVLTree(compare,destroy);
	parseDirectory("testdir/", testTree);
	findInTree(testTree, "file.c");
	removeFromTree(testTree, "testdir/", "file.c");
	destroyAVLTree(testTree);
	return(0);
}
Ejemplo n.º 5
0
/* Entfernt einen Freispeicherknoten aus
 * der Freispeicherliste und dem Freispeicher-Baum
 */
void removeFreeNode(node * myNode)
{
	if (myNode==0)
		return;

	/* Loesche Speicher aus Liste */
	int index = -1;
	if (myNode->size > MAXSIZE) index = 32;
	else index = myNode->size / 8 - 1;

	node * prev = findPrevItem(myNode, freeMem[index]);
	if (prev == 0) freeMem[index] = 0;
	else prev->next = myNode->next;

	/* Loesche Speicher aus Baum */
	removeFromTree(myNode, &freeTree);
}
Ejemplo n.º 6
0
void my_free(void* ptr)
{
	node* myNode = (node*)( ((char*)ptr) - offset );
	removeFromTree(myNode, &allocTree);
	insertFreeNode(myNode);
}
Ejemplo n.º 7
0
int testBinarySearchTree(void) {
	Tree *head = NULL;
	Tree *singleNodeTree = malloc(sizeof(Tree));
	Tree *test[2];	
	if(singleNodeTree == NULL) {
		exit(EXIT_FAILURE);
	}
	singleNodeTree->value = 100;
	singleNodeTree->left = NULL;
	singleNodeTree->right = NULL;

	printf("Start Test of Binary Search Tree.\n");
	printf("Initial contents of the tree:\n");
	print_ascii_tree(head);

	printf("\nadd() 5 to the tree\n");
	head = addToTree(head, 5);
	print_ascii_tree(head);
	printf("\nadd() 2 to the tree\n");
	head = addToTree(head, 2);
	print_ascii_tree(head);
	printf("\nadd() 12 to the tree\n");	
	head = addToTree(head, 12);
	print_ascii_tree(head);
	printf("\nadd() 1 to the tree\n");	
	head = addToTree(head, 1);
	print_ascii_tree(head);
	printf("\nadd() 8 to the tree\n");	
	head = addToTree(head, 8);
	print_ascii_tree(head);
	printf("\nadd() 4 to the tree\n");	
	head = addToTree(head, 4);
	print_ascii_tree(head);
	printf("\nadd() 3 to the tree\n");	
	head = addToTree(head, 3);
	print_ascii_tree(head);
	printf("\nadd() 10 to the tree\n");	
	head = addToTree(head, 10);
	print_ascii_tree(head);
	printf("\nadd() 9 to the tree\n");	
	head = addToTree(head, 9);
	print_ascii_tree(head);	
	printf("\nadd() 11 to the tree\n");	
	head = addToTree(head, 11);
	print_ascii_tree(head);	
	printf("\nadd() 7 to the tree\n");	
	head = addToTree(head, 7);
	print_ascii_tree(head);		

	if( (test[0] = findInTree(head, 3)) == NULL) {
		printf("\nfind(3) = Value Not Found\n");
	} else {
		printf("\nfind(3) = %d\n", test[0]->value);
	}

	if( (test[0] = findInTree(head, 7)) == NULL) {
		printf("\nfind(7) = Value Not Found\n");
	} else {
		printf("\nfind(7) = %d\n", test[0]->value);
	}

	if( (test[0] = findInTree(head, 4)) == NULL) {
		printf("\nfind(4) = Value Not Found\n");
	} else {
		printf("\nfind(4) = %d\n", test[0]->value);
	}

	findParentInTree(head, head, 3, test);
	if( test[1] == NULL) {
		printf("\nfindParentOfNode(3) = Value Not Found\n");
	} else {
		printf("\nfindParentOfNode(%d) = %d\n", test[0]->value, test[1]->value);
	}

	findParentInTree(head, head, 5, test);
	if( test[1] == NULL) {
		printf("\nfindParentOfNode(5) = Value Not Found\n");
	} else {
		printf("\nfindParentOfNode(%d) = %d\n", test[0]->value, test[1]->value);
	}

	findParentInTree(head, head, 2, test);
	if( test[1] == NULL) {
		printf("\nfindParentOfNode(2) = Value Not Found\n");
	} else {
		printf("\nfindParentOfNode(%d) = %d\n", test[0]->value, test[1]->value);
	}

	findParentInTree(head, head, 9, test);
	if( test[1] == NULL) {
		printf("\nfindParentOfNode(9) = Value Not Found\n");
	} else {
		printf("\nfindParentOfNode(%d) = %d\n", test[0]->value, test[1]->value);
	}

	printf("Depth of the tree = %d\n", getTreeDepth(head, 0));
	inOrderTraversal(head);
	preOrderTraversal(head);
	postOrderTraversal(head);	
	breadthFirstSearch(head);		
	/* Delete Order: 1, 3, 12, 8, 5 */
	printf("\nbefore removing any items\n");
	print_ascii_tree(head);		
	printf("\nremove() 1 from the tree\n");	
	head = removeFromTree(head, 1);
	print_ascii_tree(head);		
	printf("\nremove() 3 from the tree\n");	
	head = removeFromTree(head, 3);
	print_ascii_tree(head);		
	printf("\nremove() 12 from the tree\n");	
	head = removeFromTree(head, 12);
	print_ascii_tree(head);		
	printf("\nremove() 8 from the tree\n");	
	head = removeFromTree(head, 8);
	print_ascii_tree(head);		
	printf("\nremove() 5 from the tree\n");	
	head = removeFromTree(head, 5);
	print_ascii_tree(head);			
	printf("\nremove() 11 from the tree\n");	
	head = removeFromTree(head, 11);
	print_ascii_tree(head);				
	printf("Depth of the tree = %d\n", getTreeDepth(head, 0));
	inOrderTraversal(head);
	breadthFirstSearch(head);		

	printf("\nsinglNodeTests start here: \n");
	print_ascii_tree(singleNodeTree);
	inOrderTraversal(singleNodeTree);

	printf("\n remove() 1 from tree\n");
	if(removeFromTree(singleNodeTree, 1) == NULL) {
		printf("Node Not Found, nothing removed\n");
	}
	printf("Depth of the singleNodeTree = %d\n", getTreeDepth(singleNodeTree, 0));	

	printf("\n remove() 100 from tree\n");
	singleNodeTree = removeFromTree(singleNodeTree, 100);
	printf("Depth of the singleNodeTree = %d\n", getTreeDepth(singleNodeTree, 0));

	return EXIT_SUCCESS;
}
Ejemplo n.º 8
0
bool hashTree::remove(char * vendorName)
{
    removeFromTree(vendorName);
    removeFromTable(vendorName);
    return true;
}