python - How to create a recursive linked node insertion sort algorithm?
问题描述
Here's what Ive figured out till now but I'm confused as to what I have to do next.
@d <= lnk.value:
TypeError: '<=' not supported between instances of 'int' and 'LinkNode'
解决方案
The error:
File "D:/insertionsort.py", line 21, in insert
if lnk == None or val.value <= lnk.value:
TypeError: '<=' not supported between instances of 'int' and 'LinkNode'
Is telling you that when <=
gets called, lnk.value
is a LinkNode
, which
can't be compared with an int
(which is what val.value
is). In the line:
lnkNew = LinkNode(lnk, insert(val, lnk.rest))
You're setting lnkNew.value
to lnk
; it should be lnk.value
.
推荐阅读
- pandas - Pandas - 尝试通过使用 Pandas 读取文件来保存一组文件,但只保存最新的文件
- robots.txt - robots.txt:通配符是否也意味着没有字符?
- spring - 多部分 REST 操作的客户端代码
- reactjs - { apollo-client, react, grapgql } 处理多重加载的好方法是什么?
- dart - 如何使用多个列表视图构建器滚动页面
- abap - 调用不带命名参数的动态方法
- javascript - 如何获取json数组中多个键的键并操作它们的数据?
- arrays - 如果切片器项中不存在数组项,则忽略它(切片器使用数组过滤)
- php - 我们可以告诉浏览器设置一个特定的标题字段吗?
- angular - Angular如何在不同视图中保留user_id