我正在学习使用 Python,并开始编写一些代码。我尝试了一百种可能的更改,但我不知道如何修复它。这是我的代码:
from random import *
from time import *
L = []
for m in range(0,100):
L.append(randint(0,100))
def quicksort(L, first, last):
i = first
j = last
pivote = (L[i] + L[j]) / 2
while i < j:
while L[i] < pivote:
i+=1
while L[j] > pivote:
j-=1
if i <= j:
x == L[j]
L[j] == L[i]
L[i] == x
i+=1
j-=1
if first < j:
L == quicksort(L, first, j)
if last > i:
L == quicksort(L, i, last)
return L
start = time()
print ("Disordered:" , L)
L = quicksort(L, L[0], L[len(L)-1])
print ("Ordered:" ,L)
print ("%.2f seconds" % (time() - start))
这是错误:
Traceback (most recent call last):
File "/Users/Ricardo/Desktop/QuickSortR.py", line 48, in <module>
L = quicksort(L, L[0], L[len(L)-1])
File "/Users/Ricardo/Desktop/QuickSortR.py", line 28, in quicksort
x == L[j]
NameError: global name 'x' is not defined
谢谢你帮助我!