首页 > 解决方案 > 将节点添加到结束函数有什么作用

问题描述

我想知道这个add_node_end函数到底是做什么的:

typedef struct listint_s {
    char *a;
    char *b;
    struct listint_s *next;
} listint_t;

listint_t *add_node_end(listint_t **head, char *a, char *b) {
    listint_t *tmp_node, *new_node;

    new_node = malloc(sizeof(listint_t));
    if (!new_node)
        return (NULL);
    new_node->a = a;
    new_node->b = b;
    new_node->next = NULL;
    if (!*head) {
        *head = new_node;
        return (*head);
    }
    tmp_node = *head;
    while (tmp_node->next)
        tmp_node = tmp_node->next;
    tmp_node->next = new_node;
    return (*head);
}

标签: clinked-listsingly-linked-list

解决方案


推荐阅读