- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsertionSortAlgorithm.py
More file actions
Latest commit
45 lines (35 loc) · 1.32 KB
/
Copy pathinsertionSortAlgorithm.py
File metadata and controls
45 lines (35 loc) · 1.32 KB
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
42
43
44
45
importtime
importsortingUtils
fromsortingUtilsimportisSorted, wait
definsertionSort(array, delay):
startTime=time.perf_counter()
whilenotisSorted(array) andsortingUtils.sorting:
foriinrange(1, len(array)):
k=array[i]
j=i-1
sortingUtils.selectedIndices.clear()
sortingUtils.comparedIndices.clear()
sortingUtils.comparedIndices.append(i)
sortingUtils.comparisons+=1
whilej>=0andk<array[j]:
sortingUtils.selectedIndices.clear()
sortingUtils.selectedIndices.append(j)
array[j+1] =array[j]
j-=1
sortingUtils.swaps+=1
sortingUtils.swapDataSound.play()
sortingUtils.sortTimeVisual=time.perf_counter() -startTime
array[j+1] =k
wait(delay)
yield
definsertionSortNoVisible(array):
startTime=time.perf_counter()
whilenotisSorted(array) andsortingUtils.sorting:
foriinrange(1, len(array)):
k=array[i]
j=i-1
whilej>=0andk<array[j]:
array[j+1] =array[j]
j-=1
array[j+1] =k
sortingUtils.sortTime=time.perf_counter() -startTime