单链表的19种基本操作 函数,末尾添加元素

来源:互联网 发布:陈小春版鹿鼎记 知乎 编辑:程序博客网 时间:2024/06/11 00:24

下面的文章写的很好,建议大家仔细阅读,下面是我在阅读时候的一些想法,供大家参考。

https://www.zybuluo.com/quinn/note/77064

1,函数11,在单链表的末尾添加一个元素,有点问题,没有考虑到 L 时 NULL的情况,个人觉得考虑进来,并修改 *L,如下:

void insert_end_node(Node **L, elemType x) 

{ Node *insert_node, *last = NULL; 

Node *p = (*L); 

insert_node = (Node*)malloc(sizeof(Node)); 

last->next = insert_node; insert_node->element = x;  

insert_node->next = NULL;

if(*L == NULL) 

*L = insert_node; return; 

while (p != NULL) 

{

last = p; 

p = p->next; 

printf("insert_end_list运行成功,向末尾添加元素%d!\n", x); 

return;

}


0 0
原创粉丝点击