def minimum_apres_n(li, n):
	"""
	Renvoie l'indice du plus petit element apres l'indice n inclus.
	"""
	elem_min = li[n]
	indice_min = n
	for i in range(n, len(li)):
		if li[i] < elem_min:
			elem_min = li[i]
			indice_min = i
	return indice_min

def echange(li, n, p):
	"""
	Echange l'element d'indice n et celui d'indice p dans li.
	"""
	tempo = li[n]
	li[n] = li[p]
	li[p] = tempo

def tri_selection(li):
	"""
	Trie la liste li dans l'ordre croissant en utilisant l'algorithme du tri par selection.
	"""
	for i in range(len(li)):
		min_actuel = minimum_apres_n(li, i)
		echange(li, i, min_actuel)



def tri_insertion(li):
	for i in range(1, len(li)):
		ind = i
		while ind > 0 and li[ind] < li[ind-1]:
			echange(li, ind, ind-1)
			ind = ind - 1



## Exemples

# l1 = [12, 18, 5, 9, 12, 17]
# tri_selection(l1)
# print("li après tri par sélection : ", l1)

l2 = [12, 18, 5, 9, 12, 17]
tri_insertion(l2)
print("li après tri par insertion : ", l2)
