我正在尝试计算曼哈顿距离的python 8 Puzzle 的不同类型的排序算法。完成气泡并合并。专门尝试实现快速排序。
下面的代码给了我错误:
TypeError: unsupported operand type(s) for +: 'NoneType' and 'list'
队列是具有元素的 8 个拼图状态的节点列表(当前状态、父节点、深度、路径成本、manhattanDistance、MisplacedTilesDistance)
任何改进的指针
def quickSort(queue, length):
less = []
pivotList = []
more = []
returnList = []
if length <= 1:
return queue
else:
if queue == []:
return
else:
pivot = queue[0][3] + queue[0][4]
for i in queue:
if i[3]+i[4] < pivot:
less.append(i)
print less
input("yes")
elif i[3]+i[4] > pivot:
more.append(i)
else:
pivotList.append(i)
less = quickSort(less, length)
more = quickSort(more, length)
#returnList.append(less, pivotList, more)
return less + pivotList + more