首页 > 其他 > 详细

utlist使用总结

时间:2021-08-26 09:16:19      阅读:28      评论:0      收藏:0      [点我收藏+]

参考:https://blog.csdn.net/a123441/article/details/90374650

utlist.h获取(可直接粘贴):https://gitee.com/yanbib/libcoap2/blob/master/utlist.h

使用手册(暂时只找到uthash的):http://troydhanson.github.io/uthash/userguide.html#_delete_item

使用utlist双向链表可以模拟栈、队列。示例:

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <limits.h>
 4 #include <string.h>
 5 #include "utlist.h"
 6 #include "uthash.h"
 7 
 8 #define LEN 5
 9 
10 typedef struct el {
11     char name[LEN];
12     struct el *next;
13     struct el *prev;
14 } el;
15 
16 int Cmp(el *a, el *b)
17 {
18     return strcmp(a->name, b->name);
19 }
20 
21 int main()
22 {
23     el *head = NULL;
24     el *input = NULL;
25     el *temp = NULL;
26 
27     for (int i = 0; i < LEN; i++) {
28         input = (el *)malloc(sizeof(el));
29         memset(input, 0, sizeof(el));
30         scanf("%s", input->name);
31         DL_APPEND(head, input);
32     }
33 
34     DL_FOREACH(head, temp) {
35         printf("%s\n", temp->name);
36     }
37     printf("\n==========\n");
38 
39     DL_SORT(head, Cmp);
40 
41     DL_FOREACH(head, temp) {
42         printf("%s\n", temp->name);
43     }
44     printf("\n==========\n");
45     
46     DL_DELETE(head, head);
47     printf("%s\n", head->name);
48     printf("%s\n", head->prev->name);
49     DL_DELETE(head, head->prev);
50     printf("%s\n", head->name); 
51     printf("%s\n", head->prev->name);
52 
53     return 0;
54 }

运行示例:

技术分享图片

utlist使用总结

原文:https://www.cnblogs.com/hemeiwolong/p/15187656.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!