From a3cc1510952b1f4198d73741e11a0fe19084af76 Mon Sep 17 00:00:00 2001 From: eduardagoulart Date: Mon, 1 Oct 2018 21:41:47 -0300 Subject: [PATCH] bubble sort --- algorithms/bubblesort.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/algorithms/bubblesort.py b/algorithms/bubblesort.py index e69de29..f76c311 100644 --- a/algorithms/bubblesort.py +++ b/algorithms/bubblesort.py @@ -0,0 +1,15 @@ +def bubble_sort(lista_entrada): + for i, valor_atual in enumerate(lista_entrada): + try: + if lista_entrada[i + 1] < valor_atual: + lista_entrada[i] = lista_entrada[i + 1] + lista_entrada[i + 1] = valor_atual + bubble_sort(lista_entrada) + except IndexError: + pass + return lista_entrada + + +lista_entrada = [72, 35, 8, 90, 65, 44, 31, 22, 29, 78, 83] +bubble_sort(lista_entrada) +print(lista_entrada)