/**
 * main - Entry point
 *
 * Return: Always 0 (Success)
 */
int main(void)
{
    binary_tree_t *root;

    root = binary_tree_node(NULL, 98);
    root->left = binary_tree_node(root, 12);
    root->right = binary_tree_node(root, 402);
    binary_tree_print(root);
    printf("\n");
    binary_tree_insert_right(root->left, 54);
    binary_tree_insert_right(root, 128);
    binary_tree_print(root);
    return (0);
}
Exemple #2
0
static char * test_binary_tree_insertion() {
    /*
     * Test case based on http://www.csee.umbc.edu/courses/undergraduate/341/fall98/frey/ClassNotes/Class18/avl.html
     */
    int aux;
    BinaryTreeNode* node;
    aux = 0;
    node = NULL;

    printf("Initial configuration: \n");
    node = binary_tree_insert(10, node, &aux);

    binary_tree_print(node, 1);
    printf("\n ------------------- \n");

    node = binary_tree_insert(20, node, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------ \n");

    node = binary_tree_insert(30, node, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------ \n");

    node = binary_tree_insert(40, node, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------ \n");

    node = binary_tree_insert(50, node, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------ \n");

    node = binary_tree_insert(0, node, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------ \n");

    node = binary_tree_insert(70, node, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------ \n");

    node = binary_tree_insert(60, node, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------ \n");

    mu_assert("test_binary_tree_insertion", 1 == 1);
    return 0;
}
/**
 * main - Entry point
 *
 * Return: Always 0 (Success)
 */
int main(void)
{
    binary_tree_t *root;
    size_t leaves;

    root = binary_tree_node(NULL, 98);
    root->left = binary_tree_node(root, 12);
    root->right = binary_tree_node(root, 402);
    binary_tree_insert_right(root->left, 54);
    binary_tree_insert_right(root, 128);
    binary_tree_print(root);

    leaves = binary_tree_leaves(root);
    printf("Leaves in %d: %lu\n", root->n, leaves);
    leaves = binary_tree_leaves(root->right);
    printf("Leaves in %d: %lu\n", root->right->n, leaves);
    leaves = binary_tree_leaves(root->left->right);
    printf("Leaves in %d: %lu\n", root->left->right->n, leaves);
    return (0);
}
/**
 * main - Entry point
 *
 * Return: Always 0 (Success)
 */
int main(void)
{
    binary_tree_t *root;
    size_t size;

    root = binary_tree_node(NULL, 98);
    root->left = binary_tree_node(root, 12);
    root->right = binary_tree_node(root, 402);
    binary_tree_insert_right(root->left, 54);
    binary_tree_insert_right(root, 128);
    binary_tree_print(root);

    size = binary_tree_size(root);
    printf("Size of %d: %lu\n", root->n, size);
    size = binary_tree_size(root->right);
    printf("Size of %d: %lu\n", root->right->n, size);
    size = binary_tree_size(root->left->right);
    printf("Size of %d: %lu\n", root->left->right->n, size);
    return (0);
}
Exemple #5
0
static char * test_binary_tree_insertion_4() {
    int aux;
    BinaryTreeNode* node;
    aux = 0;
    node = NULL;

    printf("Initial configuration: \n");

    node = binary_tree_insert(15, node, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------- \n");

    node = binary_tree_insert(20, node, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------- \n");

    node = binary_tree_insert(24, node, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------- \n");

    node = binary_tree_insert(10, node, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------- \n");

    node = binary_tree_insert(13, node, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------- \n");

    node = binary_tree_insert(7, node, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------- \n");

    node = binary_tree_insert(30, node, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------- \n");


    node = binary_tree_insert(36, node, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------- \n");

    node = binary_tree_insert(25, node, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------- \n");

    node = binary_tree_remove_node(node, 24, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------- \n");

    node = binary_tree_remove_node(node, 20, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------- \n");

//    node = binary_tree_insert(8, node, &aux);
//    binary_tree_print(node, 1);
//    printf("\n ------------------- \n");
//
//    node = binary_tree_remove_node(node, 53, &aux);
//    binary_tree_print(node, 1);
//    printf("\n ------------------- \n");
//
//    node = binary_tree_remove_node(node, 11, &aux);
//    binary_tree_print(node, 1);
//    printf("\n ------------------- \n");
//
//    node = binary_tree_remove_node(node, 8, &aux);
//    binary_tree_print(node, 1);
//    printf("\n ------------------- \n");

    mu_assert("test_binary_tree_insertion", 1 == 1);
    return 0;
}
Exemple #6
0
static char * test_binary_tree_insertion_3() {
    int aux;
    BinaryTreeNode* node;
    aux = 0;
    node = NULL;

    printf("Initial configuration: \n");

    node = binary_tree_insert(14, node, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------- \n");

    node = binary_tree_insert(17, node, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------- \n");

    node = binary_tree_insert(11, node, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------- \n");

    node = binary_tree_insert(7, node, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------- \n");

    node = binary_tree_insert(53, node, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------- \n");

    node = binary_tree_insert(4, node, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------- \n");

    node = binary_tree_insert(13, node, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------- \n");


    node = binary_tree_insert(12, node, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------- \n");

    node = binary_tree_insert(8, node, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------- \n");

    node = binary_tree_remove_node(node, 53, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------- \n");

    node = binary_tree_remove_node(node, 11, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------- \n");

    node = binary_tree_remove_node(node, 8, &aux);
    binary_tree_print(node, 1);
    printf("\n ------------------- \n");

    mu_assert("test_binary_tree_insertion", 1 == 1);
    return 0;
}
Exemple #7
0
static char * test_binary_tree_creation() {
    int aux;
    BinaryTreeNode* node;
    aux = 0;
    node = NULL;

    printf("Initial configuration: \n");
    node = binary_tree_insert(10, node, &aux);
    node = binary_tree_insert(20, node, &aux);
    node = binary_tree_insert(30, node, &aux);
    node = binary_tree_insert(40, node, &aux);
    node = binary_tree_insert(50, node, &aux);
    node = binary_tree_insert(60, node, &aux);
    node = binary_tree_insert(80, node, &aux);
    node = binary_tree_insert(90, node, &aux);
    node = binary_tree_insert(100, node, &aux);
    node = binary_tree_insert(110, node, &aux);
    node = binary_tree_insert(120, node, &aux);


    binary_tree_print(node, 1);
    printf("\n");
    printf("\n");
    printf("-----------------------------------\n");
    printf("\n");

    node = binary_tree_remove_node(node, 90, &aux);

    printf("Removing Node: %d \n", 90);
    binary_tree_print(node, 1);
    printf("\n");
    printf("-----------------------------------\n");

    node = binary_tree_remove_node(node, 100, &aux);

    printf("Removing Node: %d \n", 100);
    binary_tree_print(node, 1);
    printf("\n");
    printf("-----------------------------------\n");

    node = binary_tree_remove_node(node, 110, &aux);

    printf("Removing Node: %d \n", 110);
    binary_tree_print(node, 1);
    printf("\n");
    printf("-----------------------------------\n");

    node = binary_tree_remove_node(node, 80, &aux);

    printf("Removing Node: %d \n", 80);
    binary_tree_print(node, 1);
    printf("\n");
    printf("-----------------------------------\n");

    node = binary_tree_remove_node(node, 120, &aux);

    printf("Removing Node: %d \n", 120);
    binary_tree_print(node, 1);
    printf("\n");
    printf("-----------------------------------\n");

    mu_assert("erro test_binary_tree_creation", 1 == 1);
    return 0;
}