Esempio n. 1
0
bst_t bst_remove(bst_t bst, index_t index) {


    if (bst_type(bst) == isNotEmpty) {

        switch (index_compare(index, bst)) {

        case EQ:

            switch (has_child(bst)) {

            case none:
                bst = bst_destroy(bst);
                break;

            case both:
            case justRigth:

                pair_destroy(bst->pair);
                bst->pair = pair_copy((bst->der)->pair);        /*copia el par q le sigue (der) */
                bst->der =
                    bst_remove(bst->der, pair_fst((bst->der)->pair));
                break;

            case justLeft:

                pair_destroy(bst->pair);
                bst->pair = pair_copy((bst->izq)->pair);        /*copia el par q le sigue (der) */
                bst->izq =
                    bst_remove(bst->izq, pair_fst((bst->izq)->pair));
                break;

            }

            break;

        case LT:
            bst->izq = bst_remove(bst->izq, index);
            break;

        case GT:
            bst->der = bst_remove(bst->der, index);
            break;

        }


    }


    return (bst);

}
Esempio n. 2
0
bst_t bst_copy(bst_t bst) {

    bst_t copy = bst_empty();

    switch (bst_type(bst)) {

    case isNull:
        bst_destroy(copy);
        return (NULL);
        break;

    case isEmpty:
        break;

    case isNotEmpty:
        copy->pair = pair_copy(bst->pair);
        copy->izq = bst_copy(bst->izq);
        copy->der = bst_copy(bst->der);
        break;
    }

    assert(bst_is_equal(bst, copy));
    /*POST*/ return (copy);

}
Esempio n. 3
0
pair_t bst_max(bst_t bst) {
    pair_t result = NULL;

    if (bst != NULL) {
        if (bst->right == NULL) {
            result = pair_copy(bst->pair);
        } else {
            result = bst_max(bst->right);
        }
    }

    return (result);
}