void inorder_tree_walk(node_t* root)
{
    if (root) {
        inorder_tree_walk(root->left);
        printf("%d ", root->key);
        inorder_tree_walk(root->right);
    }
}
Example #2
0
//__________________________________________________________________________
//                               algo from Korman
//__________________________________________________________________________
void inorder_tree_walk(struct node* vroot)
{
	if (vroot != 0) {
		inorder_tree_walk(vroot->left);
		printf("%i ", vroot->value);
		inorder_tree_walk(vroot->right);
	}
}
Example #3
0
void inorder_tree_walk(const Node *T)
{
	if (NIL == T)
		return;

	inorder_tree_walk(LEFT(T));
	printf("%d(%d), ", KEY(T), SIZE(T));
	inorder_tree_walk(RIGHT(T));
}
Example #4
0
void
inorder_tree_walk(RB_TREE *T, RB_NODE *x)
{
    if (x != T->nil) {
        inorder_tree_walk(T, x->left);
        printf("%d ", x->key);
        inorder_tree_walk(T, x->right);
    }
}
/*
 *
 * note: refer to the pseudocode in page 288.
 * */
int inorder_tree_walk(bstnode *phead) {
    assert(phead);

    if (phead->pleft) {
        inorder_tree_walk(phead->pleft);
    }

    printf("%d\t", phead->ival);

    if (phead->pright) {
        inorder_tree_walk(phead->pright);
    }

    return 0;
}
Example #6
0
int main(int argc, const char * argv[]) {
    Binary_tree * bt;
    Binary_tree * min;
    Binary_tree * max;
    Binary_tree * successor;
    Binary_tree * presuccessor;
    //Binary_tree * search_result;
    Binary_tree * after_delete;
    bt = inserttree(bt,10);
    bt = inserttree(bt,9);
    bt = inserttree_recursion(bt,7);
    bt = inserttree(bt,18);
    bt = inserttree(bt,16);
    bt = inserttree(bt,12);
    bt = inserttree(bt,20);
    bt = inserttree(bt,19);
    
    //printf("%d\n",bt->right->num);
    //search_result = tree_search(bt,19);
    //printf("%d",search_result->parent->num);
    inorder_tree_walk(bt);
    //successor = tree_successor(bt->right);
    //printf("%d\n",successor->num);
    //printf("%d\n",bt->right->left->num);
    //presuccessor = tree_presuccessor(bt->right->left);
    //min = minimum_recursion(bt);
    //max = maximum_recurison(bt);
    //after_delete = tree_delete(bt, bt->left);
    //inorder_tree_walk_another(after_delete);
    //printf("%d\n",presuccessor->num);
    //printf("%d\n",min->num);
    //printf("%d\n",max->num);
    //printf("%d\n",bt->right->parent->num);
    return 0;
}
int main(int argc, char* argv[])
{
    node_t* root = NULL;
    root = tree_insert(root, 12);
    root = tree_insert(root, 10);
    root = tree_insert(root, 16);
    root = tree_insert(root, 6);
    root = tree_insert(root, 18);
    root = tree_insert(root, 15);
    
    node_t* n = tree_search(root, 10);
    if (n) {
        printf("find 10\n");
        
        node_t* next = tree_succesor(n);
        if (next) {
            printf("next of 10 is %d\n", next->key);
        }
    }
    
    root = tree_delete(root, 16);
    
    printf("inorder_tree_walk\n");
    inorder_tree_walk(root);
    printf("\n");
    
    return 0;
}
Example #8
0
int
main(void)
{
    //int         i;
    RB_TREE     *T;

    T = tree_init();

    node_insert(T, 23);
    node_insert(T, 94);
    node_insert(T, 32);
    node_insert(T, 84);
    node_insert(T, 12);
    node_insert(T, 8);
    node_insert(T, 82);
    node_insert(T, 31);
    node_insert(T, 59);
    node_insert(T, 41);
    node_insert(T, 73);

    //for ( i = 0 ; i < 1000 ; i++ ) {
    //    key = rand() % 1000;
    //    node_insert(T, key);
    //}


    inorder_tree_walk(T, T->root);
    printf("\n");

    node_delete(T, 32);
    node_delete(T, 8);
    node_delete(T, 4);

    printf("after delete 32, 8, 4:\n");
    inorder_tree_walk(T, T->root);
    printf("\n");

    printf("sucessor of 23 is %d\n", rbtree_successor(T, rbtree_search(T, T->root, 23))->key);
    printf("predecessor of 84 is %d\n", rbtree_predecessor(T, rbtree_search(T, T->root, 84))->key);
    printf("the maximun is %d\n", rbtree_maximum(T, T->root)->key);
    printf("the minimum is %d\n", rbtree_minimum(T, T->root)->key);

    node_destory(T, T->root);
    tree_destory(T);

    exit(0);
}
Example #9
0
int main(int argc, char** argv)
{
	struct tree* tree;
	ALLOC_PTR(tree);
	assert(tree != 0);

	tree_ini(tree, 50);

//	int tree_node_add(struct tree* vtree, int value)
	int rc = tree_node_add(tree, 10);
	rc = tree_node_add(tree, 20);
	rc = tree_node_add(tree, 1);
	rc = tree_node_add(tree, 4); //fail
	rc = tree_node_add(tree, 120);
	rc = tree_node_add(tree, 110);
	rc = tree_node_add(tree, 130);
	rc = tree_node_add(tree, 100); //fail
	rc = tree_node_add(tree, 3); //fail

	inorder_tree_walk(tree->root);

	size_t start = 0;
	size_t finish = 0;

	struct node* t = 0;
	start = checkpoint();
	t = tree_search(tree->root, 120);
	finish = checkpoint();
	printf("\nrecursuve search %i\n", t->value);
	printf("time recursive: %zu\n", finish - start);

	start = finish = 0;
	start = checkpoint();
	t = iterative_tree_search(tree->root, 120);
	finish = checkpoint();
	printf("\niterative search %i\n", t->value);
	printf("time iterative: %zu\n", finish - start);

	t = tree_minimum(tree->root);
	printf("minimum: %i \n", t->value);

	t = tree_maximum(tree->root);
	printf("maximum: %i \n", t->value);


	struct node* temp;
	ALLOC_PTR(temp);
	assert(temp != 0);
	temp->value = 64;
	temp->right = 0;
	temp->left = 0;
//T - дерево, z - указатель на вставляемую вершину
	tree_insert(tree, temp);

	inorder_tree_walk(tree->root);
/*
	tree = tree_node_add(tree, 1, 1);
	//bad bug
	tree = tree_node_add(tree, 4, 1);
	tree = tree_node_add(tree, 2, 0);
	tree = tree_node_add(tree, 3, 0);
	tree = tree_node_add(tree, 4, 1);
*/
	//tree_print(tree);

/*
	tree_fini(tree);
*/

	return 0;
}