相关疑难解决方法(0)

链表添加到尾部,混乱

Visual Studio 2008 C

我无法理解的这个链表是在if语句的else部分添加尾部.

当分配头部和尾部时,node_temp的内存地址同时指向tail和head都指向相同的内存位置.

但是,在else部分中,头部实际上仍然指向尾部.有些东西我无法解释,也不了解其他部分?

我希望有人能为我解释得更好.

static struct convert_temp
{
    size_t cel;
    size_t fah;
    struct convert_temp *next;
} *head = NULL, *tail = NULL;

/** Add the new converted temperatures on the list */
void add(size_t cel, size_t fah)
{
    struct convert_temp *node_temp = NULL; /* contain temp data */

    node_temp = malloc(sizeof(*node_temp));

    if(node_temp == NULL)
    {
        fprintf(stderr, "Cannot allocate memory [ %s ] : [ %d ]\n",
            __FUNCTION__, __LINE__);
        exit(0);
    }

    /* Assign data */
    node_temp->cel = …
Run Code Online (Sandbox Code Playgroud)

c linked-list

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

c ×1

linked-list ×1