int
main (void)
{
	bst_node_t *test_node = NULL;
	int i = 10;
	char c = 'a';
	struct test_struct {
		int tsi;
		char tsc;
		float f;
	};
	float f = 4.24;

	struct test_struct test_obj = {42, 'Z', 4.24};
	struct test_struct *tsptr;

	test_node = bst_node_create ((void *)i);
	i = (int) test_node->data;
	assert(10 == i);
	
	test_node = bst_node_create ((void *) c);
	assert('a' == (char) test_node->data);

	test_node = bst_node_create ((void *) &test_obj);
	tsptr = (struct test_struct *) test_node->data;	
	assert(42 == tsptr->tsi &&  'Z' == tsptr->tsc && tsptr->f == f);

	return 0;
}
/** Insert specified data to the right of the parent node */
int 
bst_node_insert_to_right (bst_node_t *parent, void *data)
{
	bst_node_t *node = bst_node_create(data);

	if (!node)
		return -ENOMEM;

	parent->right = node;

	return 0;
}
예제 #3
0
int
bst_insert(bst_t *tree, void *data, comparefn compare)
{
    bst_node_t *node = NULL;

    if (! tree)
        return -1;

    node = bst_node_create(data);

    if (!node)
        return -ENOMEM;

    return bst_insert_node (tree, node, compare);
}
예제 #4
0
파일: bst.c 프로젝트: cubicdaiya/tree
bool bst_insert(bst_node_t *root, bst_elem_t elem, mpool_t **pool) {
    bst_node_t **branch;
    
    if (elem < root->elem) {
        branch = &root->left;
    } else if (elem > root->elem) {
        branch = &root->right;
    } else {
        return false;
    }
    
    if (*branch == NULL) {
        *branch = bst_node_create(elem, pool);
        return true;
    } else {
        return bst_insert(*branch, elem, pool);
    }
}
예제 #5
0
파일: bst.c 프로젝트: cubicdaiya/tree
bst_node_t *bst_create(bst_elem_t elem, mpool_t **pool) {
    return bst_node_create(elem, pool);
}