39 lines
740 B
C
39 lines
740 B
C
|
|
#ifndef AVL_H
|
||
|
|
#define AVL_H
|
||
|
|
|
||
|
|
#include <stddef.h>
|
||
|
|
|
||
|
|
typedef struct AVLTree AVLTree;
|
||
|
|
typedef struct AVLNode AVLNode;
|
||
|
|
|
||
|
|
typedef enum {
|
||
|
|
AVL_OK,
|
||
|
|
AVL_BAD_ALLOC,
|
||
|
|
AVL_NULL_ARG,
|
||
|
|
AVL_DUPLICATE,
|
||
|
|
AVL_EMPTY,
|
||
|
|
} AvlErr;
|
||
|
|
|
||
|
|
|
||
|
|
typedef enum {
|
||
|
|
AVL_ROT_NONE,
|
||
|
|
AVL_ROT_LEFT,
|
||
|
|
AVL_ROT_RIGHT,
|
||
|
|
AVL_ROT_LEFT_RIGHT,
|
||
|
|
AVL_ROT_RIGHT_LEFT,
|
||
|
|
} AvlRotation;
|
||
|
|
|
||
|
|
AVLTree *avl_create(void);
|
||
|
|
AvlErr avl_destroy(AVLTree **tree);
|
||
|
|
AvlErr avl_insert(AVLTree *tree, int key);
|
||
|
|
AvlErr avl_node_count(AVLTree *tree, size_t *out);
|
||
|
|
AvlErr avl_height(AVLTree *tree, int *out);
|
||
|
|
|
||
|
|
void avl_print(AVLTree *tree);
|
||
|
|
void avl_print_inorder(AVLTree *tree);
|
||
|
|
|
||
|
|
const char *avl_rotation_name(AvlRotation rot);
|
||
|
|
const char *avl_err_name(AvlErr err);
|
||
|
|
|
||
|
|
#endif /* AVL_H */
|