MCPcopy Create free account
hub / github.com/bterwijn/memory_graph / insertion_sort

Function insertion_sort

src/insertion_sort.py:12–24  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

10mg.config.type_to_slicer[float] = (mg.Slicer(), mg.Slicer())
11
12def insertion_sort(data):
13 for i in range(1, len(data)):
14 key = data[i]
15 j = i
16 while j > 0:
17 smaller = data[j-1]
18 if smaller < key:
19 break
20 j -= 1
21 if j < i:
22 print('swapping', data[j:i], 'with', key)
23 data[j+1:i+1] = data[j:i]; data[j] = key
24 print('unsorted:', data)
25
26n = 10
27data = [float(i) for i in range(n)]

Callers 1

insertion_sort.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected