-
Notifications
You must be signed in to change notification settings - Fork 3
/
09aula_pratica.py
43 lines (40 loc) · 1.12 KB
/
09aula_pratica.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: cp1252 -*-
# 31/05/2015
# Aula Pratica 9
# Exc 1
def select_sort(lista):
"Select Sort Method"
for index, elem in enumerate(lista):
menor = elem
for j_esimo, elem in enumerate(lista[index:]):
if elem < menor:
#lista[index] = menor
lista[j_esimo+index] = menor
menor = elem
lista[index] = menor
return lista
# Exc 2
def bubble_sort(lista):
"Bubble Sort Method"
flag = True
while flag:
flag = False
for index in range(len(lista) - 1):
#for index in range(len(lista)):
if lista[index + 1] < lista[index]:
aux = lista[index]
lista[index] = lista[index + 1]
lista[index + 1] = aux
flag = True
return lista
if __name__ == '__main__':
# Aula pratica 9
# Exc 1
lista = [9,8,4,5,1,9,8,6,4,8,9,2,3]
print ("Lista desordenada")
print (lista)
print ("Lista ordenada select_sort")
print (select_sort(lista))
# Exc 2
print ("Lista ordenada bubble_sort")
print (bubble_sort(lista))