Compare commits
No commits in common. "2a265f75ae332fc8febc876e132ce63a0a7aac65" and "fc3597fca58868a1f4a422257759ed7f454108af" have entirely different histories.
2a265f75ae
...
fc3597fca5
2 changed files with 14 additions and 60 deletions
|
|
@ -46,47 +46,6 @@ typedef struct FledastyRedBlackTreeNode_##name {
|
||||||
typedef struct { \
|
typedef struct { \
|
||||||
size_t size; \
|
size_t size; \
|
||||||
FledastyRedBlackTreeNode_##name *top; \
|
FledastyRedBlackTreeNode_##name *top; \
|
||||||
} FledastyRedBlackTree_##name; \
|
} FledastyRedBlackTree_##name;
|
||||||
\
|
|
||||||
FledastyError fledasty_red_black_tree_##name##_free(FledastyRedBlackTree_##name *current_red_black_tree); \
|
|
||||||
\
|
|
||||||
static inline bool fledasty_red_black_tree_##name##_is_empty(const FledastyRedBlackTree_##name *current_red_black_tree) { return current_red_black_tree == NULL || current_red_black_tree->size == 0; }
|
|
||||||
|
|
||||||
#define FLEDASTY_RED_BLACK_TREE_IMPLEMENT(key_type, value_type, name, compare_key_function, key_less_than_function) \
|
|
||||||
FledastyError fledasty_red_black_tree_##name##_free(FledastyRedBlackTree_##name *current_red_black_tree) { \
|
|
||||||
if (current_red_black_tree != NULL) { \
|
|
||||||
return FLEDASTY_ERROR_INVALID_POINTER; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
FledastyRedBlackTreeNode_##name *current_node = current_red_black_tree->top; \
|
|
||||||
while (current_node != NULL) { \
|
|
||||||
if (current_node->left != NULL) { \
|
|
||||||
current_node = current_node->left; \
|
|
||||||
} else if (current_node->right != NULL) { \
|
|
||||||
current_node = current_node->right; \
|
|
||||||
} else if (current_node->parent != NULL) { \
|
|
||||||
current_node = current_node->parent; \
|
|
||||||
if (current_node->left != NULL) { \
|
|
||||||
if (hallocy_free(current_node->left) != HALLOCY_ERROR_NONE) { \
|
|
||||||
return FLEDASTY_ERROR_FAILED_ALLOCATION; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
current_node->left = NULL; \
|
|
||||||
} else { \
|
|
||||||
if (hallocy_free(current_node->right) != HALLOCY_ERROR_NONE) { \
|
|
||||||
return FLEDASTY_ERROR_FAILED_ALLOCATION; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
current_node->right = NULL; \
|
|
||||||
} \
|
|
||||||
} else { \
|
|
||||||
hallocy_free(current_node); \
|
|
||||||
current_node = NULL; \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
return FLEDASTY_ERROR_NONE; \
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,6 @@ FLEDASTY_BINARY_SEARCH_TREE_DEFINE(int, int, int_int)
|
||||||
FLEDASTY_BINARY_SEARCH_TREE_IMPLEMENT(int, int, int_int, compare_integers, integer_less_than_integer)
|
FLEDASTY_BINARY_SEARCH_TREE_IMPLEMENT(int, int, int_int, compare_integers, integer_less_than_integer)
|
||||||
|
|
||||||
FLEDASTY_RED_BLACK_TREE_DEFINE(int, int, int_int)
|
FLEDASTY_RED_BLACK_TREE_DEFINE(int, int, int_int)
|
||||||
FLEDASTY_RED_BLACK_TREE_IMPLEMENT(int, int, int_int, compare_integers, integer_less_than_integer)
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
FledastyQueue_int test_queue = { 0, 0, 0, 0, NULL };
|
FledastyQueue_int test_queue = { 0, 0, 0, 0, NULL };
|
||||||
|
|
@ -382,10 +381,6 @@ int main() {
|
||||||
printf("Biggest key is %d with the value %d\n", max_key, max_value);
|
printf("Biggest key is %d with the value %d\n", max_key, max_value);
|
||||||
|
|
||||||
fledasty_binary_search_tree_int_int_free(&test_search_tree);
|
fledasty_binary_search_tree_int_int_free(&test_search_tree);
|
||||||
|
|
||||||
FledastyRedBlackTree_int_int test_red_black_tree = { 0, NULL };
|
|
||||||
|
|
||||||
fledasty_red_black_tree_int_int_free(&test_red_black_tree);
|
|
||||||
printf("Done\n");
|
printf("Done\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue