void dict_dump(dict_t dict, FILE * fd) { assert(dict != NULL); list_t current = list_empty(); current = bst_to_list(dict->data, current); list_dump(current, fd); current = list_destroy(current); }
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); }
/* Dump the given 'dict' in the given file descriptor 'fd'.*/ void dict_dump(dict_t dict, FILE * fd) { /*Precondition verification*/ assert(fd != NULL); assert(dict != NULL); list_t list = bst_to_list(dict->data, list_empty()); list_dump(list, fd); list_destroy(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); }