-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInplaceInsertionSort.py
More file actions
43 lines (30 loc) · 897 Bytes
/
Copy pathInplaceInsertionSort.py
File metadata and controls
43 lines (30 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import random
from time import time
def CreatList(n):
alist = []
for i in range(n, 0, -1):
alist.append(random.randint(0, n))
return alist
def Inplace_InsertionSort(L):
for i in range(1, len(L)):
currentvalue = L[i]
while i > 0 and L[i - 1] > currentvalue:
L[i] = L[i - 1]
i -= 1
L[i] = currentvalue
def performace(lenList):
seqOri = CreatList(lenList)
seq1 = list(seqOri)
begin = time()
Inplace_InsertionSort(seq1)
end = time()
diff = (end - begin) * 1000
print("Inplace_InsertionSort: " + str(diff))
print("seq1: " + str(seq1))
print("--------------------------------------------------------------------------------------------------------")
if __name__ == '__main__':
performace(50)
performace(100)
#performace(500)
#performace(1000)
#performace(10000)