Lesson5-
import time
def selectionSort(alist):
length = len(alist)
for nLastPosition in range(length-1, 0, -1):
maxIndex = 0
for numIndex in range(0, nLastPosition+1):
if alist[numIndex] > alist[maxIndex]:
maxIndex = numIndex
temp = alist[nLastPosition]
alist[nLastPosition] = alist[maxIndex]
alist[maxIndex] = temp
return alist
N = 1
alist = [26,54,93,17,77,31]*N
start = time.time()
sortList = selectionSort(alist)
end = time.time()
print (end-start)
|
run
| edit
| history
| help
|
0
|
|
|