Linux内核之旅 链表实现
#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内核之旅 链表实现的更多相关文章
- linux内核数据结构之链表
linux内核数据结构之链表 1.前言 最近写代码需用到链表结构,正好公共库有关于链表的.第一眼看时,觉得有点新鲜,和我之前见到的链表结构不一样,只有前驱和后继指针,而没有数据域.后来看代码注释发现该 ...
- MOOC Linux内核之旅小结【转】
转自:https://blog.csdn.net/titer1/article/details/45345123 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csd ...
- Linux内核之旅
http://www.kerneltravel.net/ Linux内核之旅 Linux Kernel Travel
- linux内核数据结构之链表【转】
转自:http://www.cnblogs.com/Anker/p/3475643.html 1.前言 最近写代码需用到链表结构,正好公共库有关于链表的.第一眼看时,觉得有点新鲜,和我之前见到的链表结 ...
- 拒绝造轮子!如何移植并使用Linux内核的通用链表(附完整代码实现)
在实际的工作中,我们可能会经常使用链表结构来存储数据,特别是嵌入式开发,经常会使用linux内核最经典的双向链表 list_head.本篇文章详细介绍了Linux内核的通用链表是如何实现的,对于经常使 ...
- linux内核中的链表
1.内核中的链表 linux内核链表与众不同,他不是把将数据结构塞入链表,而是将链表节点塞入数据,在2.1内核中引入了官方链表,从此内核中所有的链表使用都采用此链表,千万不要在重复造车轮子了!链表实现 ...
- linux内核的双链表list_head、散列表hlist_head
一.双链表list_head 1.基本概念 linux内核提供的标准链表可用于将任何类型的数据结构彼此链接起来. 不是数据内嵌到链表中,而是把链表内嵌到数据对象中. 即:加入链表的数据结构必须包含一个 ...
- 陈莉君教授: 回望踏入Linux内核之旅
本文系转载,著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 作者: 陈莉君 来源: 微信公众号linux阅码场(id: linuxdev) 初次踏入Linux 几多耕耘,几多收获 ...
- Linux内核之旅 List_entry()
#include "iostream" #define List_entry(type,member)\ (type *)(()->data)) ) using namesp ...
随机推荐
- gtd好文两篇收藏
http://www.jianshu.com/p/bf5e8a9761f5 http://blog.sina.com.cn/s/blog_4e0f66b80100m73i.html
- 1011 最大公约数GCD
1011 最大公约数GCD 基准时间限制:1 秒 空间限制:131072 KB 输入2个正整数A,B,求A与B的最大公约数. Input 2个数A,B,中间用空格隔开.(1<= A,B < ...
- node express 学习2
上次我们的express已经安装好了 接下来我们修改渲染引擎为html // view engine setup app.set('views', path.join(__dirname, 'view ...
- Linux下/etc/resolv.conf 配置DNS客户
文件/etc/resolv.conf配置DNS客户,它包含了主机的域名搜索顺序和DNS服务器的地址,每一行应包含一个关键字和一个或多个的由空格隔开的参数.下面是一个例子文件: search mydom ...
- [LeetCode]题解(python):037-Sudoku Solver
题目来源 https://leetcode.com/problems/sudoku-solver/ Write a program to solve a Sudoku puzzle by fillin ...
- ecshop
if($cat_id == '205'){ $smarty->display('cat1.dwt', $cache_id); }elseif($cat_id == '2'){ $smarty-& ...
- php保存远程文件到本地的方法
用到了ob_start();<?php header("Content-type:text/html charset=utf-8"); if(!empty($_POST['p ...
- 记录:在老XPS1330上安装CentOS7
下图是设置时的图片,注意分区设置. 下图是安装成功的画面. 下图是在Gnome桌面环境打开Firefox上本博客的画面. 注意点: 1.安装时没啥特殊的,就两点,一是要分区设置好,图省事就让自动分区: ...
- 破解Mysql数据库密码
破解Mysql数据库密码 点我,点我,破解mysql数据库密码:
- vim中.swp文件处理
参考: http://blog.csdn.net/lingdxuyan/article/details/4993868 http://www.cnblogs.com/softwaretesting/a ...