Java教程

utlist使用总结

本文主要是介绍utlist使用总结,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

参考: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使用总结的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!