C语言:数据结构之单链表(四)
本篇谈一谈单链表的改,具体操作就是找到他,然后修改元素即可,上一篇有相关代码,可以参考。改函数代码如下:
void Correct(LinkList header, int site_, char letter_)
{
LinkList q = Search_Site(header,site_);
q->letter = letter_;
} main函数如下:(修改第6,8,3位)
int main()
{
printf("This is Struct_Data:\n\n");
LinkList head = Init_linklist();
AddLetter_Tail(head,'H');
AddLetter_Tail(head,'i');
AddLetter_Tail(head,',');
AddLetter_Tail(head,'L');
AddLetter_Tail(head,'i');
AddLetter_Tail(head,'n');
AddLetter_Tail(head,'u');
AddLetter_Tail(head,'x');
AddLetter_Tail(head,'.');
PrintList(head);
printf("len: %d\n",Get_Length(head));
printf("Correct 6,8,3 \n");
Correct(head,6,'@');
Correct(head,8,'@');
Correct(head,3,'@');
PrintList(head);
printf("len: %d\n",Get_Length(head));
return 0;
} 结果如下:
https://img2023.cnblogs.com/blog/3227584/202307/3227584-20230716100529491-1578505167.png
至此,单链表的增删改查就谈完了,只需理解它的本质是干什么,代码就很好写了。
总结:①改比较简单,只要函数正确只需套用函数解决问题即可。
②学习的过程就是反复总结和反复学习,不需要每天去了解但是隔段时间就得去主动看看,继而久之就根深蒂固了。
以上只是本人的理解和所见,如有不同见解和看法,欢迎在评论区批评指正。
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
页:
[1]