首页 > 解决方案 > 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'

标签: pythonrecursionlinked-list

解决方案


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.


推荐阅读