02dlist-base

list.h
typedef int elem_t;

struct node_info {
    elem_t data;
    struct node_info *prev;
    struct node_info *next;
};

struct list_info {
    struct node_info *head;
    void (*add)(struct list_info *,
            struct node_info *); 
    void (*add_tail)(struct list_info *,
            struct node_info *); 
    void (*del)(struct list_info *,
            struct node_info *); 
    void (*for_each)(struct list_info *,
            void (*)(struct node_info*));
};

#define list_for_each(cur, head) \
    for (cur = (head)->next; \
        cur != (head); \
        cur = (cur)->next)

void list_init(struct list_info *); 
void list_destroy(struct list_info *); 


list.c

#include <stdio.h>
#include <stdlib.h>
#include "list.h"


/* 灏.ode?..?颁袱涓..?昏.??rev
 * prev?.ext蹇.』?搁.锛..?.??..
 */
static void __list_add(struct node_info *node,
        struct node_info *prev,
        struct node_info *next)
{
    node->prev = prev;
    node->next = next;
    prev->next = node;
    next->prev = node;
}

static void list_add(struct list_info *info, 
        struct node_info *node)
{
    __list_add(node, info->head, info->head->next);
}

static void list_add_tail(struct list_info *info, 
        struct node_info *node)
{
    __list_add(node, info->head->prev, info->head);
}


 

static void list_del(struct list_info *info,
        struct node_info *node)
{
    node->prev->next = node->next;
    node->next->prev = node->prev;
    node->prev = node;
    node->next = node;
}

static void for_each(struct list_info *info,
        void (*todo)(struct node_info *)) 
{
    struct node_info *cur = info->head->next;

    for (; cur != info->head; cur = cur->next) {
        todo(cur);
    }   
}


 

void list_init(struct list_info *info)
{
    info->head = (struct node_info *)malloc(sizeof(struct node_info));
    info->head->data = 0;
    info->head->prev = info->head;
    info->head->next = info->head;

    info->add = list_add;
    info->add_tail = list_add_tail;
    info->del = list_del;
    info->for_each = for_each;
}

void list_destroy(struct list_info *info)
{
    struct node_info *cur = info->head->next;

    for (; cur != info->head; cur = info->head->next) {
        list_del(info, cur);
    }

    free(info->head);
}

test.c

 

#include <stdio.h>
#include "list.h"

#define LIST_LEN 10

static void print(struct node_info *node)
{
    printf("%d ", node->data);
}

int main()
{
    struct list_info list;
    list_init(&list);

    struct node_info s[LIST_LEN] = {0};

    size_t i = 0;
    for (i = 0; i < LIST_LEN; i++) {
        s[i].data = i;
        list.add_tail(&list, s + i);
    }  

    list.del(&list, s + 0);
    list.del(&list, s + 1);

/*        list.for_each(&list, print);*/
    struct node_info *cur = NULL;
    list_for_each(cur, list.head) {
        printf("%d ", cur->data);
    }  
    printf("\n");

    list_destroy(&list);

    return 0;
}


 

Looking for: ['mfix==25.1.2', 'mfix-solver=25.1.2'] warning libmamba Cache file "/home/ps/miniforge3/pkgs/cache/497deca9.json" was modified by another program warning libmamba Cache file "/home/ps/miniforge3/pkgs/cache/09cdf8bf.json" was modified by another program warning libmamba Could not parse mod/etag header warning libmamba Could not parse mod/etag header warning libmamba Could not parse mod/etag header warning libmamba Could not parse mod/etag header warning libmamba Cache file "/home/ps/miniforge3/pkgs/cache/47929eba.json" was modified by another program warning libmamba Cache file "/home/ps/miniforge3/pkgs/cache/3e39a7aa.json" was modified by another program warning libmamba Cache file "/home/ps/miniforge3/pkgs/cache/2ce54b42.json" was modified by another program warning libmamba Cache file "/home/ps/miniforge3/pkgs/cache/4ea078d6.json" was modified by another program https://mirrors.ustc.edu.cn/anaconda/cloud/menpo.. https://mfix.netl.doe.gov/s3/09d9e2e6/acf3d1bd18.. https://mirrors.ustc.edu.cn/anaconda/cloud/bioco.. https://mfix.netl.doe.gov/s3/09d9e2e6/acf3d1bd18.. https://mirrors.ustc.edu.cn/anaconda/pkgs/main/n.. https://mirrors.aliyun.com/pypi/simple/linux-64 0.4s https://mirrors.ustc.edu.cn/anaconda/pkgs/main/l.. 17.6s https://mirrors.ustc.edu.cn/anaconda/cloud/msys2.. https://mirrors.aliyun.com/pypi/simple/noarch 0.6s Multi-download failed. Reason: Transfer finalized, status: 404 [https://mirrors.aliyun.com/pypi/simple/noarch/repodata.json] 2318 bytes # >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<< Traceback (most recent call last): File "/home/ps/miniforge3/lib/python3.10/site-packages/conda/exceptions.py", line 1132, in __call__ return func(*args, **kwargs) File "/home/ps/miniforge3/lib/python3.10/site-packages/mamba/mamba.py", line 941, in exception_converter raise e File "/home/ps/miniforge3/lib/python3.10/site-packages/mamba/mamba.py", line 934, in exception_converter exit_code = _wrapped_main(*args, **kwargs) File "/home/ps/miniforge3/lib/python3.10/site-packages/mamba/mamba.py", line 892, in _wrapped_main result = do_call(parsed_args, p) File "/home/ps/miniforge3/lib/python3.10/site-packages/mamba/mamba.py", line 758, in do_call exit_code = create(args, parser) File "/home/ps/miniforge3/lib/python3.10/site-packages/mamba/mamba.py", line 632, in create return install(args, parser, "create") File "/home/ps/miniforge3/lib/python3.10/site-packages/mamba/mamba.py", line 499, in install index = load_channels(pool, channels, repos) File "/home/ps/miniforge3/lib/python3.10/site-packages/mamba/utils.py", line 129, in load_channels index = get_index( File "/home/ps/miniforge3/lib/python3.10/site-packages/mamba/utils.py", line 110, in get_index is_downloaded = dlist.download(api.MAMBA_DOWNLOAD_FAILFAST) RuntimeError: Multi-download failed. Reason: Transfer finalized, status: 404 [https://mirrors.aliyun.com/pypi/simple/noarch/repodata.json] 2318 bytes `$ /home/ps/miniforge3/bin/mamba create -n mfix-25.1.2 mfix==25.1.2 mfix-solver=25.1.2 -c conda-forge -c https://mfix.netl.doe.gov/s3/09d9e2e6/acf3d1bd18d1e8d1637bad33e96216d6//conda/dist` environment variables: CIO_TEST=<not set> CONDA_DEFAULT_ENV=base CONDA_EXE=/home/ps/miniforge3/bin/conda CONDA_PREFIX=/home/ps/miniforge3 CONDA_PROMPT_MODIFIER=(base) CONDA_PYTHON_EXE=/home/ps/miniforge3/bin/python CONDA_ROOT=/home/ps/miniforge3 CONDA_SHLVL=1 CURL_CA_BUNDLE=<not set> LD_LIBRARY_PATH=/usr/local/cuda-12.0/lib64: LD_PRELOAD=<not set> PATH=/home/ps/miniforge3/bin:/home/ps/miniforge3/condabin:/home/ps/.local/b in:/home/ps/bin:/usr/local/cuda- 12.0/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin REQUESTS_CA_BUNDLE=<not set> SSL_CERT_FILE=<not set> WINDOWPATH=2 active environment : base active env location : /home/ps/miniforge3 shell level : 1 user config file : /home/ps/.condarc populated config files : /home/ps/miniforge3/.condarc /home/ps/.condarc conda version : 23.3.1 conda-build version : not installed python version : 3.10.12.final.0 virtual packages : __archspec=1=x86_64 __cuda=12.2=0 __glibc=2.28=0 __linux=4.18.0=0 __unix=0=0 base environment : /home/ps/miniforge3 (writable) conda av data dir : /home/ps/miniforge3/etc/conda conda av metadata url : None channel URLs : https://conda.anaconda.org/conda-forge/linux-64 https://conda.anaconda.org/conda-forge/noarch https://mfix.netl.doe.gov/s3/09d9e2e6/acf3d1bd18d1e8d1637bad33e96216d6//conda/dist/linux-64 https://mfix.netl.doe.gov/s3/09d9e2e6/acf3d1bd18d1e8d1637bad33e96216d6//conda/dist/noarch http://pypi.douban.com/simple/linux-64 http://pypi.douban.com/simple/noarch https://mirrors.aliyun.com/pypi/simple/linux-64 https://mirrors.aliyun.com/pypi/simple/noarch https://mirrors.ustc.edu.cn/anaconda/cloud/linux-64 https://mirrors.ustc.edu.cn/anaconda/cloud/noarch https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/linux-64 https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/noarch https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/linux-64 https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/noarch https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/linux-64 https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/noarch https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/linux-64 https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/noarch https://mirrors.ustc.edu.cn/anaconda/pkgs/free/linux-64 https://mirrors.ustc.edu.cn/anaconda/pkgs/free/noarch https://mirrors.ustc.edu.cn/anaconda/pkgs/main/linux-64 https://mirrors.ustc.edu.cn/anaconda/pkgs/main/noarch https://repo.anaconda.com/pkgs/main/linux-64 https://repo.anaconda.com/pkgs/main/noarch https://repo.anaconda.com/pkgs/r/linux-64 https://repo.anaconda.com/pkgs/r/noarch package cache : /home/ps/miniforge3/pkgs /home/ps/.conda/pkgs envs directories : /home/ps/miniforge3/envs /home/ps/.conda/envs platform : linux-64 user-agent : conda/23.3.1 requests/2.31.0 CPython/3.10.12 Linux/4.18.0-348.el8.x86_64 centos/8.5.2111 glibc/2.28 UID:GID : 1000:1000 netrc file : None offline mode : False An unexpected error has occurred. Conda has prepared the above report.
07-18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值