学习“系统程序员成长计划-走近专业程序员(上)”

双向链表

 

以前手把手的时候写过,硬盘里还保存有代码, 以前写的时候还去看了glib的实现,要不要作弊? 呵呵、、当然不要,这次完全按照自己的理解来。

 

  1. typedef struct _List List;

  2. struct _List;
  3. {
  4.    void* data;
  5.    List* prev;
  6.    List* next;
  7. };


  8. List* list_new (void)
  9. {
  10.     List* thiz = NULL;

  11.     thiz = (List*) malloc (sizeof(List));

  12.     return thiz;
  13. }


  14. void list_free (List* thiz)
  15. {
  16.     if (thiz)
  17.         free (thiz);
  18. }

  19. List* list_last (List* thiz)
  20. {
  21.     if (!thiz) return NULL;
  22.    
  23.     List* node = thiz;

  24.     while (node->next)
  25.         node = node -> next;

  26.     return node;
  27. }

  1. List* list_append (List* thiz, void* data)
  2. {
  3.     List* node = list_new ();

  4.     node -> data = data;

  5.     return thiz;
  1. }

这个网吧真不习惯、、、中午休息写。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值