我在这里找不到我的错误,如果有人可以帮助我,那就太好了。
def heapsort (lista) :
n= len(lista)-1
k= n/2
while (k>0) :
downheap(lista,n,k)
k-=1
while (n>=0) :
(lista[1]),(lista[n])=(lista[n]),(lista[1])
n-=1
return downheap(lista, n, 1)
return lista
def downheap (lista, n, k) :
v= lista[k]
while (k<=(n/2)) :
j=k+k
if (j<n and (lista[j]) == (lista[j])) :
break
(lista[k]) = (lista[j])
k = j
lista[k] = v
错误:
>>> heapsort([4,2,3,1])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 5, in heapsort
File "<stdin>", line 2, in downheap
TypeError: list indices must be integers, not float