如何将列表标题和尾部添加到链接列表

时间:2019-11-22 01:55:37

标签: c data-structures linked-list

   STUDENT *create_empty_list()
   {

    STUDENT *p_new_list;

        if((p_new_list = (STUDENT*) malloc(sizeof(STUDENT))) == NULL)
        { 
            printf("\nError #%d in create_empty_list.", HEADER_ALLOC_ERROR);
            exit(HEADER_ALLOC_ERROR);       
        }
        p_new_list->id_number = LIST_HEADER;

        if((p_new_list->p_next_student = (STUDENT*) malloc(sizeof(STUDENT))) == NULL)
        {
            printf("\nError #%d in create_empty_list.", TRAILER_ALLOC_ERROR);
            exit(TRAILER_ALLOC_ERROR);  
        }
        p_new_list->p_next_student->p_next_student = LIST_TRAILER;
        p_new_list->p_next_student->p_next_student = NULL;

        return p_new_list;
    }

我不确定如何将头和尾正确地连接到节点上。

0 个答案:

没有答案