在单链表结构中的替换也利用了遍历模式。这种情况下,我们在链表结构中搜索一个给定项或一个给定位置,并且用新的项替换该项。第一个操作,即替换一个给定的项,并不需要假定目标项在链表结构中。如果目标项不存在,那就不会发生替换,并且该操作返回False。如果目标项存在,新的项会替换它,并且该操作返回True。代码如下:
还有一个替换第i项的操作,形式如下:
两种替换操作在平均情况下都是线性的。
结束!
在单链表结构中的替换也利用了遍历模式。这种情况下,我们在链表结构中搜索一个给定项或一个给定位置,并且用新的项替换该项。第一个操作,即替换一个给定的项,并不需要假定目标项在链表结构中。如果目标项不存在,那就不会发生替换,并且该操作返回False。如果目标项存在,新的项会替换它,并且该操作返回True。代码如下:
还有一个替换第i项的操作,形式如下:
两种替换操作在平均情况下都是线性的。
结束!
单链表逆置
链表结构的顺序搜索和遍历是类似的,因为也必须从第1个节点开始且沿着
仅做学习记录。
单链表
微信搜索????「TanLiuYi00」,关注这个写干货的程序员,回复「算法」,即可获取算法电子书籍~ ...
java实现单链表常见操作
举报文章
请选择举报类型
补充说明
0/200
上传截图
格式支持JPEG/PNG/JPG,图片不超过1.9M