Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2088177
  • 博文数量: 288
  • 博客积分: 10594
  • 博客等级: 上将
  • 技术积分: 3469
  • 用 户 组: 普通用户
  • 注册时间: 2006-10-27 19:27
文章分类

全部博文(288)

文章存档

2012年(4)

2011年(30)

2010年(40)

2009年(32)

2008年(71)

2007年(79)

2006年(32)

分类: C/C++

2008-04-27 16:53:04

 

立下此码, 过段时间再看是否有进步!

#include <stdio.h>
#include <malloc.h>

struct list {
    struct list *prev, *next;
};

#define list_init(head) \
        (head)->next = (head);\
        (head)->prev = (head) \


void __list_add(struct list *new, struct list *prev, struct list *next)

{

    prev->next = new

    new->prev = prev;

    new->next = next;

    next->prev = new;

}

 

void list_add(struct list *new, struct list *head)
{
    __list_add(new, head, head->next);
}

 

void __list_del(struct list *prev, struct list *next)
{
    prev->next = next;

    next->prev = prev;

}

void list_del(struct list *enpry)
{
   __list_del(enpty->prev, enpty->next);
}

 


int main(void)
{

    int i;
    struct list *head, *tmp;

    head = (struct list*)malloc(sizeof(struct list));

    list_init(head);

    for (i = 0; i < 10; i++)

    {

        tmp = (struct list*)malloc(sizeof(struct list));

        list_add(tmp, head);

    }

    list_del(tmp);
}

阅读(1044) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~