1 Star 0 Fork 3

chendl111/simple-libevent

forked from ivanallen/simple-libevent 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
queue-test.c 1.29 KB
一键复制 编辑 原始数据 按行查看 历史
ivanallen 提交于 2017-04-07 15:59 . first commit
#include <stdio.h>
#include <string.h>
#include "queue.h"
struct person {
TAILQ_ENTRY(person) male;
TAILQ_ENTRY(person) female;
char name[20];
int age;
};
void print(struct person *p) {
printf("name = %s, age = %02d\n", p->name, p->age);
}
int main() {
// 定义队头
TAILQ_HEAD(male_list, person) malequeue;
TAILQ_HEAD(female_list, person) femalequeue;
// 初始化
TAILQ_INIT(&malequeue);
TAILQ_INIT(&femalequeue);
struct person p1, p2, p3, p4, p5, p6;
strcpy(p1.name, "allen");
p1.age = 20;
strcpy(p2.name, "luffy");
p2.age = 21;
strcpy(p3.name, "nami");
p3.age = 19;
strcpy(p4.name, "zoro");
p4.age = 22;
strcpy(p5.name, "robin");
p5.age = 28;
strcpy(p6.name, "vivi");
p6.age = 28;
// 插入元素
TAILQ_INSERT_HEAD(&malequeue, &p1, male);
TAILQ_INSERT_HEAD(&malequeue, &p2, male);
TAILQ_INSERT_TAIL(&malequeue, &p4, male);
TAILQ_INSERT_HEAD(&femalequeue, &p3, female);
TAILQ_INSERT_AFTER(&femalequeue, &p3, &p5, female);
TAILQ_INSERT_BEFORE(&p5, &p6, female);
struct person *e;
TAILQ_FOREACH(e, &malequeue, male) {
print(e);
}
TAILQ_FOREACH(e, &femalequeue, female) {
print(e);
}
print(TAILQ_LAST(&malequeue, male_list));
printf("%p\n", *(((struct male_list*)malequeue.tqh_last)->tqh_last));
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/chendl111/simple-libevent.git
[email protected]:chendl111/simple-libevent.git
chendl111
simple-libevent
simple-libevent
master

搜索帮助