有时间练习下linux下的queue.h这个程序
2012-09-26 09:00
218 查看
下面是测试代码.
#include <stdio.h>
#include <stdlib.h>
#include <sys/queue.h>
struct foo {
int a, b, c;
LIST_ENTRY(foo) pointers;
};
LIST_HEAD(foo_list, foo);
int main(void)
{
LIST_HEAD(foo_list, foo) head;
LIST_INIT(&head);
struct foo *item = malloc(sizeof(struct foo));
item->a = 69;
item->b = 123;
LIST_INSERT_HEAD(&head, item, pointers);
LIST_FOREACH(item, &head, pointers)
{
printf("a = %d b = %d\n", item->a, item->b);
}
while (!LIST_EMPTY(&head))
{
item = LIST_FIRST(&head);
LIST_REMOVE(item, pointers);
free(item);
}
return (0);
}
#include <stdio.h>
#include <stdlib.h>
#include <sys/queue.h>
struct foo {
int a, b, c;
LIST_ENTRY(foo) pointers;
};
LIST_HEAD(foo_list, foo);
int main(void)
{
LIST_HEAD(foo_list, foo) head;
LIST_INIT(&head);
struct foo *item = malloc(sizeof(struct foo));
item->a = 69;
item->b = 123;
LIST_INSERT_HEAD(&head, item, pointers);
LIST_FOREACH(item, &head, pointers)
{
printf("a = %d b = %d\n", item->a, item->b);
}
while (!LIST_EMPTY(&head))
{
item = LIST_FIRST(&head);
LIST_REMOVE(item, pointers);
free(item);
}
return (0);
}
相关文章推荐
- linux下c++多线程下用CLOCK()函数统计程序运行时间 2012-12-11 12:46:01 分类: C/C++ clock()函数的功能: 这个函数返回从“开启这个程序进程”到
- <linux程序设计> 第四章 [ 程序参数 / 环境变量 / 日期与时间]
- 二分法实现插入排序,时间复杂度O(nlgn),算法导论练习2.3,linux纯C实现
- Linux Linux程序练习十三(信号阻塞,捕获)
- Linux Linux程序练习十四(多进程压力测试)
- Linux Linux程序练习六
- C语言linux环境下使用gettimeofday函数得到程序运行时间
- linux下程序运行时间的获取方法,
- linux引导程序为什么要把自己加载到内存的7c00h这个特定的地方?
- Linux 每日一练习!!!!!!!!!!sleep 表示等待时间
- 编写一个C语言语句,要求输出这个程序需要运行的时间(用clock()做) 该怎么写?
- linux 统计程序运行时间
- 关于linux下的socket程序 响应时间的问题
- Linux Linux程序练习十(网络编程大文件发送)
- 判断序列中是否存在两个元素之和为x,时间复杂度O(nlgn),算法导论练习2.3,linux纯C实现
- 记录make结束时间,其他Linux程序其实也可以
- linux 每日一练习:父程序与子程序的概念
- linux计算程序运行时间
- 编写多线程程序,模拟多个人通过一个山洞。这个山洞每次只能通过一个人,每个人通过山洞的时间为2秒(sleep)。
- Linux下计算程序运行时间的一个简单方法