MCPcopy Create free account
hub / github.com/geekcomputers/Python / insertion_sort

Function insertion_sort

insertion_sort.py:14–34  ·  view source on GitHub ↗

sort list in assending order INPUT: list=list of values to be sorted n=size of list that contains values to be sorted OUTPUT: list of sorted values in assending order

(list, n)

Source from the content-addressed store, hash-verified

12
13
14def insertion_sort(list, n):
15 """
16 sort list in assending order
17
18 INPUT:
19 list=list of values to be sorted
20 n=size of list that contains values to be sorted
21
22 OUTPUT:
23 list of sorted values in assending order
24 """
25 for i in range(0, n):
26 key = list[i]
27 j = i - 1
28 # Swap elements witth key iff they are
29 # greater than key
30 while j >= 0 and list[j] > key:
31 list[j + 1] = list[j]
32 j = j - 1
33 list[j + 1] = key
34 return list
35
36
37def insertion_sort_desc(list, n):

Callers 1

insertion_sort.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected