标签:span 删除 sam ons parameter count sts lib 查找树
AVL树的名字来源于它的发明作者G.M. Adelson-Velsky 和 E.M. Landis。AVL树是最先发明的自平衡二叉查找树(Self-Balancing Binary Search Tree,简称平衡二叉树)。
AVL树又称平衡二叉搜索树,它能保证二叉树高度相对平衡,尽量降低二叉树的高度,提高搜索效率。单纯的二叉搜索树在最坏的情况下插入查找删除等操作时间复杂度会是O(N),AVL树使得增删查改的时间复杂度为O(lgN). (ps:这里的lgN指的是log以2为底的N)
AVL树特点:
struct avl_node { /** * Linked list node for supporting easy iteration and multiple * elments with the same key. * * this must be the first element of an avl_node to * make casting for lists easier */ struct list_head list; /** * Pointer to parent node in tree, NULL if root node */ struct avl_node *parent; /** * Pointer to left child */ struct avl_node *left; /** * Pointer to right child */ struct avl_node *right; /** * pointer to key of node */ const void *key; /** * balance state of AVL tree (0,-1,+1) */ signed char balance; /** * true if first of a series of nodes with same key */ bool leader; };
struct avl_tree { /** * Head of linked list node for supporting easy iteration * and multiple elments with the same key. */ struct list_head list_head; /** * pointer to the root node of the avl tree, NULL if tree is empty */ struct avl_node *root; /** * number of nodes in the avl tree */ unsigned int count; /** * true if multiple nodes with the same key are * allowed in the tree, false otherwise */ bool allow_dups; /** * pointer to the tree comparator * * First two parameters are keys to compare, * third parameter is a copy of cmp_ptr */ avl_tree_comp comp; /** * custom pointer delivered to the tree comparator */ void *cmp_ptr; };
/** * Prototype for avl comparators * @param k1 first key * @param k2 second key * @param ptr custom data for tree comparator * @return +1 if k1>k2, -1 if k1<k2, 0 if k1==k2 */ typedef int (*avl_tree_comp) (const void *k1, const void *k2, void *ptr);
参考:
1. 【数据结构】AVL树详解
标签:span 删除 sam ons parameter count sts lib 查找树
原文地址:https://www.cnblogs.com/embedded-linux/p/9193038.html