-
Notifications
You must be signed in to change notification settings - Fork 0
/
algorythmes_2_go.py
29 lines (23 loc) · 1.06 KB
/
algorythmes_2_go.py
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
# In the following lines we got some standart sort algoryhtmes. Nothing special about. When u want it easy just do
# yourlist.sort(), hint u can also sort strings or chars or build a key to sort the list by your own demands.
def bubblesort(unsortedlist):
n = len(unsortedlist)
for i in range(n - 1):
for j in range(0, n - i - 1):
if unsortedlist[j] > unsortedlist[j + 1]:
unsortedlist[j], unsortedlist[j + 1] = unsortedlist[j + 1], unsortedlist[j]
def insertionsort(unsortedlist):
for i in range(1, len(unsortedlist)):
key = unsortedlist[i]
j = i - 1
while j >= 0 and key < unsortedlist[j]:
unsortedlist[j + 1] = unsortedlist[j]
j -= 1
unsortedlist[j + 1] = key
def selectionsort(unsortedlist):
for i in range(len(unsortedlist)):
min_idx = i
for j in range(i + 1, len(unsortedlist)):
if unsortedlist[min_idx] > unsortedlist[j]:
min_idx = j
unsortedlist[i], unsortedlist[min_idx] = unsortedlist[min_idx], unsortedlist[i]