且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在C中实现一个双向链表

更新时间:2022-06-10 04:51:47

这里主要有两个问题:

  1. free(first):这不是必需的,因为您希望保存刚分配的内存,而不要删除它.

  1. free(first) : This is not required as you wish to save the memory you just allocated, not delete it.

您的 insertAtBeginning()函数返回指向 head 的指针,因此在 main()中,您将在其中调用此函数将其更改为 head1 = insertAtBeginning(i,head1); 这样也可以保存您的头部.

Your insertAtBeginning() function returns a pointer to head, so in main(), where you are calling this function change it to head1=insertAtBeginning(i, head1); This way your head is also saved.

这是经过两次修改的代码:

Here's the code with the two edits :

http://ideone.com/nXwc8z