Exemple #1
0
bool list_is_equal(list_t list, list_t other) {
	bool result = true;
	
	while(result && list!=NULL && other!=NULL) {
		if(!index_is_equal(pair_fst(list->elem),pair_fst(other->elem))) {
			result = false;
		}
		if(!data_is_equal(pair_snd(list->elem),pair_snd(other->elem))) {
			result = false;
		}
		list = list->next;
		other = other->next;
	}
	
	return result && list == NULL && other == NULL;
}
data_t bst_search(bst_t bst, index_t index) {


    if (bst_type(bst) == isNotEmpty) {

        switch (index_compare(index, bst)) {

        case EQ:
            return (pair_snd(bst->pair));
            break;

        case LT:
            return (bst_search(bst->izq, index));
            break;

        case GT:
            return (bst_search(bst->der, index));
            break;

        }

    }

    return (NULL);

}
Exemple #3
0
bst_t bst_copy(bst_t bst) {
    bst_t result = bst_empty();
    if (bst != NULL) {
        result = bst_add(result, index_copy(pair_fst(bst->pair)),
                         data_copy(pair_snd(bst->pair)));
        result->right = bst_copy(bst->right);
        result->left = bst_copy(bst->left);
    }
    return result;
}
Exemple #4
0
data_t list_search(list_t list, index_t index) {
	
	list_t current = list;
	while(current != NULL && !index_is_equal(pair_fst(current->elem),index)) {
		current = current->next;
	}
	
	data_t result = NULL;
	if(current!=NULL) {
		result = pair_snd(current->elem);
	}
	current = NULL;
	return result;	
}
Exemple #5
0
data_t bst_search(bst_t bst, index_t index) {
    data_t data = NULL;
    if (bst != NULL) {
        if (index_is_equal(index, pair_fst(bst->pair))) {
            data = pair_snd(bst->pair);
        } else {
            if (index_is_less_than(index, pair_fst(bst->pair))) {
                data = bst_search(bst->left, index);
            } else {
                data = bst_search(bst->right, index);
            }
        }
    }
    return (data);
}
Exemple #6
0
list_t bst_to_list(bst_t bst, list_t list) {
    if (bst != NULL) {
        index_t index = index_copy(pair_fst(bst->pair));
        data_t data = data_copy(pair_snd(bst->pair));

        if (bst->left != NULL) {
            list = bst_to_list(bst->left, list);
        }
        list = list_append(list, index, data);
        if (bst->right != NULL) {
            list = bst_to_list(bst->right, list);
        }

        index = NULL;
        data = NULL;
    }
    return (list);
}
list_t bst_to_list(bst_t bst, list_t list) {

    index_t indexc;
    data_t datac;


    if (bst_type(bst) == isNotEmpty) {

        indexc = index_copy(pair_fst(bst->pair));
        datac = data_copy(pair_snd(bst->pair));

        list = list_append(bst_to_list(bst->izq, list), indexc, datac);

        list = bst_to_list(bst->der, list);

    }

    return (list);

}
Exemple #8
0
void list_dump(list_t list, FILE * fd) {

	list_t current = list;
	char* index;
	char* data;
	while(current!=NULL) {
	
		index = index_to_string(pair_fst(current->elem));
		data = data_to_string(pair_snd(current->elem));
		
		fprintf(fd,"%s: %s",index,data);
		current = current->next;
		if(current!=NULL) {
			fprintf(fd,"\n");
		}
		
		free(index);
		free(data);
		index = NULL;
		data = NULL;
	}
	
}
Exemple #9
0
list_t list_copy(list_t list) {
	
	list_t result = list_empty(),current=list;
	
	index_t index_cop = NULL;
	data_t data_cop = NULL;
	
	while(current!=NULL) {
		index_cop = index_copy(pair_fst(current->elem));
		data_cop = data_copy(pair_snd(current->elem));
		
		result = list_append(result,index_cop,data_cop);
		
		current = current->next;
	}
	current = NULL;
	index_cop = NULL;
	data_cop = NULL;
	
	assert(list_is_equal(list,result));
	
	return result;
}