aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/lib/algo/avl_tree.h8
-rw-r--r--lib/algo/avl_tree.c4
2 files changed, 7 insertions, 5 deletions
diff --git a/include/lib/algo/avl_tree.h b/include/lib/algo/avl_tree.h
index 4467fd1..4400aa6 100644
--- a/include/lib/algo/avl_tree.h
+++ b/include/lib/algo/avl_tree.h
@@ -8,9 +8,11 @@
#define AvlHeight_t uint8_t
+typedef bool_t (*AvlComparator)(void*, void*);
+
struct AVLNode {
void* data;
- bool_t (*compare)(void*, void*);
+ AvlComparator compare;
struct AVLNode* left;
struct AVLNode* right;
AvlHeight_t height;
@@ -32,10 +34,10 @@ struct AVLNode* right_rotate(struct AVLNode* parent);
struct AVLNode* left_rotate(struct AVLNode* parent);
// Create AVL node
-struct AVLNode* create_avl_node(void* data, bool_t (*compare)(void*, void*));
+struct AVLNode* create_avl_node(void* data, AvlComparator compare);
// Insert data into AVL tree
-struct Result avl_insert(struct AVLNode* node, void* data, bool_t (*compare)(void*, void*));
+struct Result avl_insert(struct AVLNode* node, void* data, AvlComparator compare);
// In-order traversal print pointer
void print_in_order(struct AVLNode* root);
diff --git a/lib/algo/avl_tree.c b/lib/algo/avl_tree.c
index 3b5c8aa..9ac5d47 100644
--- a/lib/algo/avl_tree.c
+++ b/lib/algo/avl_tree.c
@@ -57,7 +57,7 @@ struct AVLNode* left_rotate(struct AVLNode* parent)
}
// Create AVL node
-struct AVLNode* create_avl_node(void* data, bool_t (*compare)(void*, void*))
+struct AVLNode* create_avl_node(void* data, AvlComparator compare)
{
struct AVLNode* node = (struct AVLNode*)malloc(sizeof(struct AVLNode));
if (node == NULL) {
@@ -72,7 +72,7 @@ struct AVLNode* create_avl_node(void* data, bool_t (*compare)(void*, void*))
}
// Insert data into AVL tree
-struct Result avl_insert(struct AVLNode* node, void* data, bool_t (*compare)(void*, void*))
+struct Result avl_insert(struct AVLNode* node, void* data, AvlComparator compare)
{
struct Result result;
// 1. Standard BST insertion