From dc63e6aab34b7c5ca3008b2a4c29483e22e0276f Mon Sep 17 00:00:00 2001 From: Lucas Magnum Date: Tue, 20 Nov 2018 23:28:27 +0100 Subject: [PATCH] Post about sorting algorithms --- .../algoritmos_ordenacao_usando_python.rst | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 content/algoritmos_ordenacao_usando_python.rst diff --git a/content/algoritmos_ordenacao_usando_python.rst b/content/algoritmos_ordenacao_usando_python.rst new file mode 100644 index 000000000..5e5434726 --- /dev/null +++ b/content/algoritmos_ordenacao_usando_python.rst @@ -0,0 +1,98 @@ +Algoritmos de Ordenação +######################## + +:date: 2018-11-20 23:10 +:tags: python, algoritmos +:category: Python +:slug: algoritmos-ordenacao +:author: Lucas Magnum +:email: lucasmagnumlopes@gmail.com +:github: lucasmagnum +:linkedin: lucasmagnum + +Fala pessoal, tudo bom? + +Nos vídeos abaixo, vamos aprender como implementar alguns dos algoritmos de ordenação usando Python. + + +Bubble Sort +=========== + +Como o algoritmo funciona: Como implementar o algoritmo usando Python: `https://www.youtube.com/watch?v=Doy64STkwlI `_. + + +.. youtube:: Doy64STkwlI + +Como implementar o algoritmo usando Python: `https://www.youtube.com/watch?v=B0DFF0fE4rk `_. + +.. youtube:: B0DFF0fE4rk + +Código do algoritmo + +.. code-block:: python + + def sort(array): + + for final in range(len(array), 0, -1): + exchanging = False + + for current in range(0, final - 1): + if array[current] > array[current + 1]: + array[current + 1], array[current] = array[current], array[current + 1] + exchanging = True + + if not exchanging: + break + + +Selection Sort +============== + +Como o algoritmo funciona: Como implementar o algoritmo usando Python: `https://www.youtube.com/watch?v=PLvo_Yb_myrNBhIdq8qqtNSDFtnBfsKL2r `_. + + +.. youtube:: PLvo_Yb_myrNBhIdq8qqtNSDFtnBfsKL2r + +Como implementar o algoritmo usando Python: `https://www.youtube.com/watch?v=0ORfCwwhF_I `_. + +.. youtube:: 0ORfCwwhF_I + +Código do algoritmo + +.. code-block:: python + + def sort(array): + for index in range(0, len(array)): + min_index = index + + for right in range(index + 1, len(array)): + if array[right] < array[min_index]: + min_index = right + + array[index], array[min_index] = array[min_index], array[index] + + +Insertion Sort +============== + +Como o algoritmo funciona: Como implementar o algoritmo usando Python: `https://www.youtube.com/watch?v=O_E-Lj5HuRU `_. + +.. youtube:: O_E-Lj5HuRU + +Como implementar o algoritmo usando Python: `https://www.youtube.com/watch?v=Sy_Z1pqMgko `_. + +.. youtube:: Sy_Z1pqMgko + +Código do algoritmo + +.. code-block:: python + + def sort(array): + for p in range(0, len(array)): + current_element = array[p] + + while p > 0 and array[p - 1] > current_element: + array[p] = array[p - 1] + p -= 1 + + array[p] = current_element