libubox库avl树的使用例子

1. 定义一棵avl树

struct avl_tree services;

2. 初始化avl树

int avl_strcmp(const void *k1, const void *k2, void *ptr)
{
	return strcmp(k1, k2);
}

avl_init(&services, avl_strcmp, false, NULL);

3. 插入结点

struct service {
	struct avl_node avl;
	...
};

struct service *s = service_alloc(name);

avl_insert(&services, &s->avl);

 

4. 删除结点

avl_delete(&services, &s->avl);

5. 遍历结点

avl_for_each_element(&services, s, avl)
	service_dump(s);

6. 查找结点

s = avl_find_element(&services, name, s, avl);

 

    原文作者:AVL树
    原文地址: https://blog.csdn.net/liangdsing/article/details/53759922
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞