#include "stdio.h"
#include "stdlib.h" struct list_head{
struct list_head *prev;
struct list_head *next;
}; struct task{
int member;
struct list_head list;
}; #define list_entry(ptr,member,type) \
((type*)((char *)ptr-(unsigned long)&(((type*))->member))) #define Init_list(list) {&list,&list} static void list_add(struct list_head* ptr,struct list_head* n){
ptr->next=n->next;
n->next->prev=ptr;
n->next=ptr;
ptr->prev=n;
} #define for_each(list_)\
for(pos=list_.next;pos!=&list_;pos=pos->next)\
{printf("%d ",list_entry(pos,list,struct task)->member);}\
printf("\n"); void main(){
struct task* tmp;
int i;
struct list_head mylist=Init_list(mylist),*pos; for( i=;i<;i++){
tmp=(struct task*)malloc(sizeof(struct task));
scanf("%d",&(tmp->member));
list_add(&(tmp->list),&mylist);
} for_each(mylist); }

Linux内核之旅 链表实现的更多相关文章

  1. linux内核数据结构之链表

    linux内核数据结构之链表 1.前言 最近写代码需用到链表结构,正好公共库有关于链表的.第一眼看时,觉得有点新鲜,和我之前见到的链表结构不一样,只有前驱和后继指针,而没有数据域.后来看代码注释发现该 ...

  2. MOOC Linux内核之旅小结【转】

    转自:https://blog.csdn.net/titer1/article/details/45345123 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csd ...

  3. Linux内核之旅

    http://www.kerneltravel.net/ Linux内核之旅 Linux Kernel Travel

  4. linux内核数据结构之链表【转】

    转自:http://www.cnblogs.com/Anker/p/3475643.html 1.前言 最近写代码需用到链表结构,正好公共库有关于链表的.第一眼看时,觉得有点新鲜,和我之前见到的链表结 ...

  5. 拒绝造轮子!如何移植并使用Linux内核的通用链表(附完整代码实现)

    在实际的工作中,我们可能会经常使用链表结构来存储数据,特别是嵌入式开发,经常会使用linux内核最经典的双向链表 list_head.本篇文章详细介绍了Linux内核的通用链表是如何实现的,对于经常使 ...

  6. linux内核中的链表

    1.内核中的链表 linux内核链表与众不同,他不是把将数据结构塞入链表,而是将链表节点塞入数据,在2.1内核中引入了官方链表,从此内核中所有的链表使用都采用此链表,千万不要在重复造车轮子了!链表实现 ...

  7. linux内核的双链表list_head、散列表hlist_head

    一.双链表list_head 1.基本概念 linux内核提供的标准链表可用于将任何类型的数据结构彼此链接起来. 不是数据内嵌到链表中,而是把链表内嵌到数据对象中. 即:加入链表的数据结构必须包含一个 ...

  8. 陈莉君教授: 回望踏入Linux内核之旅

    本文系转载,著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 作者: 陈莉君 来源: 微信公众号linux阅码场(id: linuxdev) 初次踏入Linux 几多耕耘,几多收获 ...

  9. Linux内核之旅 List_entry()

    #include "iostream" #define List_entry(type,member)\ (type *)(()->data)) ) using namesp ...

随机推荐

  1. 地图API使用文档-以腾讯地图为例

    目录 腾讯地图API 2 1.API概览... 2 1.1 WebService API(官网注明是beta版本,可能不稳定,慎用):... 2 1.2 URL API:... 2 1.3 静态图AP ...

  2. LinQ总结

    不管是在Mvc还是在别的架构中的项目LinQ和Lambda总是经常会遇到的. 而有些LinQ的语法并不是很长用(我大部分用的是Lambda),所以有必要记录一下万一用到的时候我能很方便的找到我想找到的 ...

  3. Android源码剖析之Framework层升级版(窗口、系统启动)

    本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 看本篇文章之前,建议先查看: Android源码剖析之Framework层基础版 前面讲了frame ...

  4. crossvcl.com - 用VCL开发MacOS软件

    还没正式发布.用力戳 http://crossvcl.com/ 消息来源:Delphi G+ Group.具体信息还没完全披露,但是可以肯定的是,不是通过FireMonkey,而是通过原生的MacOS ...

  5. Python 扫面文件夹中的文件

    #coding=utf-8 import os,sys reload(sys) sys.setdefaultencoding("utf-8") def scan_files_sub ...

  6. 小米1plus MIUI RadioButton的问题

    小米1plus MIUI RadioButton不能设置setBackground(Drawable drawable);会变成黑色背景,需要单独处理

  7. [LeetCode]题解(python):053-Maximum Subarray

    题目来源 https://leetcode.com/problems/maximum-subarray/ Find the contiguous subarray within an array (c ...

  8. RaspberryPi uart

    通过调试口查看树莓派开机启动信息,学习python控制串口的方法. 参考链接: http://www.elinux.org/Serial_port_programming 硬件连接: 硬件原理图链接: ...

  9. OPENCV3.1+VS 坑我笔记!

    1.调用findContours()函数程序崩溃. 原因: >>分析opencv源代码,跟踪测试,进入工程:opencv_imgproc 发现findContours函数 是调用 _fin ...

  10. LeetCode H-Index II

    原题链接在这里:https://leetcode.com/problems/h-index-ii/ 题目: Follow up for H-Index: What if the citations a ...