免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 7045 | 回复: 12
打印 上一主题 下一主题

[C] 如何在linux c 实现list [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-03-09 15:29 |只看该作者 |倒序浏览
如题,因为需要在linux c实现一个list,收集实现方法。 希望不吝赐教。

论坛徽章:
89
水瓶座
日期:2014-04-01 08:53:31天蝎座
日期:2014-04-01 08:53:53天秤座
日期:2014-04-01 08:54:02射手座
日期:2014-04-01 08:54:15子鼠
日期:2014-04-01 08:55:35辰龙
日期:2014-04-01 08:56:36未羊
日期:2014-04-01 08:56:27戌狗
日期:2014-04-01 08:56:13亥猪
日期:2014-04-01 08:56:02亥猪
日期:2014-04-08 08:38:58程序设计版块每日发帖之星
日期:2016-01-05 06:20:00程序设计版块每日发帖之星
日期:2016-01-07 06:20:00
2 [报告]
发表于 2011-03-09 15:33 |只看该作者
这么弱的问题。

论坛徽章:
1
CU十二周年纪念徽章
日期:2013-10-24 15:41:34
3 [报告]
发表于 2011-03-09 15:36 |只看该作者
随便找找,很多的。

论坛徽章:
0
4 [报告]
发表于 2011-03-09 15:46 |只看该作者
回复 2# fender0107401


    请不要误解,只是想比较各种不同的实现。数据结构的代码在kernel里有大部分,这里只是用作交流目的。

论坛徽章:
324
射手座
日期:2013-08-23 12:04:38射手座
日期:2013-08-23 16:18:12未羊
日期:2013-08-30 14:33:15水瓶座
日期:2013-09-02 16:44:31摩羯座
日期:2013-09-25 09:33:52双子座
日期:2013-09-26 12:21:10金牛座
日期:2013-10-14 09:08:49申猴
日期:2013-10-16 13:09:43子鼠
日期:2013-10-17 23:23:19射手座
日期:2013-10-18 13:00:27金牛座
日期:2013-10-18 15:47:57午马
日期:2013-10-18 21:43:38
5 [报告]
发表于 2011-03-09 15:46 |只看该作者
跟linux没啥关系,数据结构总学过吧

论坛徽章:
0
6 [报告]
发表于 2011-03-09 15:56 |只看该作者
Linux内核里面有个很好用的list

论坛徽章:
1
射手座
日期:2013-08-21 13:11:46
7 [报告]
发表于 2011-03-09 15:58 |只看该作者
C接口编程也有自己实现的list,array,hash_list之类的

论坛徽章:
0
8 [报告]
发表于 2011-03-10 16:20 |只看该作者
这个跟系统没关系吧 你要是用C编程 就找c实现的list就成 在那个系统上都能用的

论坛徽章:
0
9 [报告]
发表于 2011-03-10 19:15 |只看该作者
linux内核list的简化版

#ifndef _LIST_H
#define _LIST_H

struct list_head
{
    struct list_head *prev;
    struct list_head *next;
};

static inline void init_list_head(struct list_head *head)
{
    head->next = head;
    head->prev = head;
}
static inline void __list_add(struct list_head *new , struct list_head *prev , struct list_head *next)
{
    new->next = next;
    new->prev = prev;
    prev->next = new;
    next->prev = new;
}

static inline void list_push_back(struct list_head *new , struct list_head *head)
{
    __list_add(new , head->prev , head);
}

static inline void list_push_front(struct list_head *new , struct list_head *head)
{
    __list_add(new , head , head->next);
}

static inline void __list_del(struct list_head *prev , struct list_head *next)
{
    prev->next = next;
    next->prev = prev;
}

static inline void list_del(struct list_head *node)
{
    __list_del(node->prev , node->next);
}

static inline int list_empty(const struct list_head *head)
{
    return (head == head->next);
}
#define offset_of(type , member) (size_t)(&((type *)0)->member)

#define container_of(ptr , type , member) \
({ \
    (type *)( (char *)ptr - offset_of(type , member)); \
})

#define list_entry(ptr , type , member) \
    container_of(ptr , type , member)

#define list_first_entry(ptr , type , member) \
   list_entry((ptr)->next , type , member)
  
#define list_for_each(pos, head) \
        for (pos = (head)->next; pos != (head); \
                pos = pos->next)

#endif// _LIST_H

论坛徽章:
0
10 [报告]
发表于 2011-03-18 13:44 |只看该作者
回复 9# hengshan

感谢回复。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP