示例#1
0
//清空树
void tree_clear(s_tree *tree, s_node *node)
{
	if (node == null)
	{
		return;
	}

	//递归清空左子树
	tree_clear(tree, node->left_child);
	node->left_child = null;
	//递归清空右子树
	tree_clear(tree, node->right_sibling);
	node->right_sibling = null;

	//如果数据项不为空
	if (node->data != null)
	{
		//释放数据项内存
		tree->free_node(node->data);
	}

	if (node == tree->root)
	{
		tree->root = null;
	}

	//释放当前节点内存
	free(node);
}
示例#2
0
void tree_clear(btNode*& root)
{
    if (root == 0) return;
    tree_clear(root->left);
    tree_clear(root->right);
    delete root;
    root = 0;
}
示例#3
0
void tree_clear(Node*& ptr)
{
  if (ptr != 0) {
    tree_clear(ptr->left_ptr());
    tree_clear(ptr->right_ptr());
    delete ptr;
    ptr = 0;
  }
}// tree_clear
示例#4
0
int func_optimize(tree* my_tree, bool* is_optimized)
{
	assert(my_tree);
	if (my_tree -> type != TR_F) return TREE_OK;
	
	assert(is_optimized);
	assert(my_tree -> right);

	

	int argc = 0;
	int ret = 0;
	int number_of_func = 0;

	CALL(count_args(my_tree, &argc));
	CALL(verify_func(my_tree, argc, &number_of_func));

	if (is_possible_func_optimize(my_tree, argc) == false) return TREE_OK;

	double argv[MAXVARS] = {};

	CALL(get_args(my_tree, argv, (const int)argc));

	double value = 0;

	CALL((math_funcs[number_of_func].func)(argv, &value));
	
	CALL(tree_destr(my_tree -> right));
	CALL(tree_clear(my_tree));
	CALL(tree_burn(my_tree, TR_N, value));
	*is_optimized = true;

	return TREE_OK;
}
示例#5
0
size_t
tr_tree_clear(tr_tree* tree)
{
    ASSERT(tree != NULL);

    return tree_clear(tree);
}
示例#6
0
size_t
tree_free(void* Tree)
{
    ASSERT(Tree != NULL);

    const size_t count = tree_clear(Tree);
    FREE(Tree);
    return count;
}
示例#7
0
size_t
tr_tree_free(tr_tree* tree)
{
    ASSERT(tree != NULL);

    size_t count = tree_clear(tree);
    FREE(tree);
    return count;
}
示例#8
0
void tree_clear(bool (*func)(tree), tree xs) { // {{{
    if (!tree_empty(xs->left)) {
        if (func(xs->left)) {
            tree_delete(xs->left);
            xs->left = NULL;
        } else {
            tree_clear(func, xs->left);
        }
    }

    if (!tree_empty(xs->right)) {
        if (func(xs->right)) {
            tree_delete(xs->right);
            xs->right = NULL;
        } else {
            tree_clear(func, xs->right);
        }
    }
} // }}}
示例#9
0
size_t
tree_free(void* Tree)
{
    tree* tree = Tree;
    ASSERT(tree != NULL);

    const size_t count = tree_clear(tree);
    FREE(tree);
    return count;
}
示例#10
0
int main() {

    slong n, i, m, prec = 60;
    flint_rand_t state;
    
    flint_printf("symplectic basis...");
    fflush(stdout);
    flint_randinit(state);

    for (n = 3; n < 10; n++)
    {
        for (i = 0; i < 5; i++)
        {
            acb_ptr x;
            tree_t tree;
 
            x = _acb_vec_init(n);
            acb_vec_set_random(x, n, state, prec, 4);

            tree_init(tree, n - 1);
            spanning_tree(tree, x, n, INT_DE);

            for (m = 2; m < 7; m++)
            {
                sec_t c;
                homol_t alpha, beta;

                sec_init(&c, m, n);
                tree_ydata_init(tree, x, n, m, prec);

                alpha = flint_malloc(c.g * sizeof(loop_t));
                beta = flint_malloc(c.g * sizeof(loop_t));

                symplectic_basis(alpha, beta, tree, c);

                homol_clear(alpha, c.g);
                homol_clear(beta, c.g);

                tree_ydata_clear(tree);
                sec_clear(c);
            }

            tree_clear(tree);
            _acb_vec_clear(x, n);
        }
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return 0;
}
示例#11
0
//清空树
void tree_clear(s_tree *tree, s_node *node)
{
	if (node == null)
	{
		return;
	}

	//递归清空左子树
	tree_clear(tree, node->left_child);
	//递归清空右子树
	tree_clear(tree, node->right_child);

	node->left_child = null;
	node->right_child = null;

	if (node == tree->root)
	{
		tree->root = null;
	}

	//释放当前节点内存
	free(node);
}
示例#12
0
//销毁树
bool tree_destroy(s_tree *tree)
{
	if (tree == null)
	{
		return false;
	}

	//清空树
	tree_clear(tree, tree->root);

	//根节点置空
	tree->root = null;

	return true;
}
示例#13
0
文件: program.c 项目: ayogodojo/colm
int colm_delete_program( program_t *prg )
{
	tree_t **sp = prg->stack_root;
	int exit_status = prg->exit_status;

	colm_tree_downref( prg, sp, prg->return_val );
	colm_clear_heap( prg, sp );

	colm_tree_downref( prg, sp, prg->error );

#if DEBUG
	long kid_lost = kid_num_lost( prg );
	long tree_lost = tree_num_lost( prg );
	long parse_tree_lost = parse_tree_num_lost( &prg->parse_tree_pool );
	long head_lost = head_num_lost( prg );
	long location_lost = location_num_lost( prg );

	if ( kid_lost )
		message( "warning: lost kids: %ld\n", kid_lost );

	if ( tree_lost )
		message( "warning: lost trees: %ld\n", tree_lost );

	if ( parse_tree_lost )
		message( "warning: lost parse trees: %ld\n", parse_tree_lost );

	if ( head_lost )
		message( "warning: lost heads: %ld\n", head_lost );

	if ( location_lost )
		message( "warning: lost locations: %ld\n", location_lost );
#endif

	kid_clear( prg );
	tree_clear( prg );
	head_clear( prg );
	parse_tree_clear( &prg->parse_tree_pool );
	location_clear( prg );

	struct run_buf *rb = prg->alloc_run_buf;
	while ( rb != 0 ) {
		struct run_buf *next = rb->next;
		free( rb );
		rb = next;
	}

	vm_clear( prg );

	if ( prg->stream_fns ) {
		char **ptr = prg->stream_fns;
		while ( *ptr != 0 ) {
			free( *ptr );
			ptr += 1;
		}

		free( prg->stream_fns );
	}

	free( prg );

	return exit_status;
}
示例#14
0
int main()
{
	char buf[256];
	char *cmd = NULL, *args = NULL;
	SearchTree tree;
	TreeNode *current = NULL;	
	tree_make_empty(&tree);
	while(1)
	{
		printf("> ");
		fgets(buf, sizeof(buf), stdin);
		cmd = strtok(buf, " \n");
		args = strtok(NULL, "\n");
		if (!cmd)
			continue;
		if (!strcmp(cmd, "quit"))
			break;
		else if (!strcmp(cmd, "clear"))
			tree_clear(&tree);
		else if (!strcmp(cmd, "help"))
			printf("%s\n", help_str);
		else if (!strcmp(cmd, "size"))
			printf("Size: %d\n", tree_size(&tree));	
		else if (!strcmp(cmd, "insert"))
			insert(args, &tree, current, ipWholeTree);
		else if (!strcmp(cmd, "insert_left"))
			insert(args, &tree, current, ipNodeLeft);
		else if (!strcmp(cmd, "insert_right"))
			insert(args, &tree, current, ipNodeRight);
		else if (!strcmp(cmd, "jump_root"))
			current = tree.root;
		else if (!strcmp(cmd, "jump_left")) {
			if (current)
				if (current->left)
					current = current->left;
		}
		else if (!strcmp(cmd, "jump_right")) {
			if (current)
				if (current->right)
					current = current->right;
		}
		else if (!strcmp(cmd, "jump_parent")) {
			if (current)
				if (current->parent)
					current = current->parent;
		}
		else if (!strcmp(cmd, "find"))
			find(args, &tree, &current);
		else if (!strcmp(cmd, "remove_subtree")) {
			tree_remove_subtree(&tree, current);
			current = NULL;
		}
		else if (!strcmp(cmd, "current"))
			print_value(current);
		else if (!strcmp(cmd, "print"))
			tree_print(&tree);
		else
			printf("Command \"%s\" not found\n", cmd);
	}
	tree_clear(&tree);
	return 0;
}
示例#15
0
void tree_clear_zero_sum(tree xs) { // {{{
    tree_clear(tree_zero_sum, xs);
} // }}}
示例#16
0
void destr(binary_tree_node*& root_ptr)
// Header file used: bintree.h
{
    tree_clear(root_ptr);
}
示例#17
0
文件: bag6.cpp 项目: tanthua/AllInOne
	bag<Item>::~bag() {
		tree_clear(root_ptr);
		root_ptr = NULL;
	}