添加节点到结束功能有什么作用

时间:2019-04-28 00:16:51

标签: c linked-list singly-linked-list

我想知道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);
}

0 个答案:

没有答案