1. added insertion-sort pseudocode and code,unittest 2. added 2.1-1 and 2.1-2 3. part of 2.1-3
23 lines
492 B
Python
23 lines
492 B
Python
__author__ = 'pezy'
|
|
|
|
|
|
def insertion_sort(lst):
|
|
for j in range(1, len(lst)):
|
|
key = lst[j]
|
|
i = j - 1
|
|
while i >= 0 and lst[i] > key:
|
|
lst[i + 1] = lst[i]
|
|
i -= 1
|
|
lst[i + 1] = key
|
|
return lst
|
|
|
|
|
|
def insertion_sort_non_increasing(lst):
|
|
for j in range(1, len(lst)):
|
|
key = lst[j]
|
|
i = j - 1
|
|
while i >= 0 and lst[i] < key:
|
|
lst[i + 1] = lst[i]
|
|
i -= 1
|
|
lst[i + 1] = key
|
|
return lst |