zoukankan      html  css  js  c++  java
  • list_head.h

    typedef struct list_head
    {
        struct list_head *prev;
        struct list_head *next;
    }list_head_t;
    
    #define container_of(ptr, type, member, ret) do { 
        ret = (type *)((char *)ptr - (long long)(&((type *)0)->member));}while(0)
    
    static inline void list_init_head(list_head_t *head)
    {
        head->next = head;
        head->prev = head;
    }
    
    static inline void __list_add(list_head_t *new_node,
                                  list_head_t *prev_node,
                                  list_head_t *next_node)
    {
        new_node->prev = prev_node;
        new_node->next = next_node;
    
        prev_node->next = new_node;
        next_node->prev = new_node;
    }
    
    static inline void __list_del(list_head_t *prev,
                                  list_head_t *next)
    {
        prev->next = next;
        next->prev = prev;
    }
    
    static inline void list_add_prev(list_head_t *new_node,
                                     list_head_t *head)
    {
        __list_add(new_node, head->prev, head);
    }
    
    static inline void list_add_next(list_head_t *new_node,
                                     list_head_t *head)
    {
        __list_add(new_node, head, head->next);
    }
    
    static inline void list_del_node(list_head_t *node)
    {
        __list_del(node->prev, node->next);
        list_init_head(node);
    }
    
    static inline int  list_is_empty(list_head_t *head)
    {
        if ( (head->next == head) && (head->prev == head) )
        {
            return 1;
        }
        
        return 0;
    }
    
    static inline list_head_t *list_del_first_node(list_head_t *head)
    {
        list_head_t *node = NULL;
    
        node = head->next;
        if ( node == head )
        {
            return NULL;
        }
    
        list_del_node(node);
    
        return node;
    }
  • 相关阅读:
    HDU 5501
    CF #324 DIV2 E题
    CF #324 DIV2 C题
    利用位操作实现加减运算(不用+ -号)
    【Leetcode】120. 三角形最小路径和
    删除排序链表中的重复元素
    【python】二分查找
    如何在不添加新数组的情况下移除元素?
    三/四 数之和,双指针法,细节很多
    【转】字符串相关操作
  • 原文地址:https://www.cnblogs.com/liuzc/p/6522423.html
Copyright © 2011-2022 走看看