From 9beea7d249ae8ae4a4f1f08ca340495584260f06 Mon Sep 17 00:00:00 2001 From: Lucas Magnum Date: Thu, 29 Nov 2018 14:03:57 +0100 Subject: [PATCH] Update post with new video about merge sort --- .../algoritmos_ordenacao_usando_python.rst | 46 +++++++++++++++++-- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/content/algoritmos_ordenacao_usando_python.rst b/content/algoritmos_ordenacao_usando_python.rst index 5e5434726..71c714302 100644 --- a/content/algoritmos_ordenacao_usando_python.rst +++ b/content/algoritmos_ordenacao_usando_python.rst @@ -1,7 +1,7 @@ Algoritmos de Ordenação ######################## -:date: 2018-11-20 23:10 +:date: 2018-11-29 13:10 :tags: python, algoritmos :category: Python :slug: algoritmos-ordenacao @@ -48,12 +48,11 @@ Código do algoritmo Selection Sort ============== -Como o algoritmo funciona: Como implementar o algoritmo usando Python: `https://www.youtube.com/watch?v=PLvo_Yb_myrNBhIdq8qqtNSDFtnBfsKL2r `_. +Como o algoritmo funciona: Como implementar o algoritmo usando Python: `https://www.youtube.com/watch?v=vHxtP9BC-AA `_. +.. youtube:: vHxtP9BC-AA -.. youtube:: PLvo_Yb_myrNBhIdq8qqtNSDFtnBfsKL2r - -Como implementar o algoritmo usando Python: `https://www.youtube.com/watch?v=0ORfCwwhF_I `_. +Como implementar o algoritmo usando Python: `https://www.youtube.com/watch?v=0ORfCwwhF_I `_. .. youtube:: 0ORfCwwhF_I @@ -96,3 +95,40 @@ Código do algoritmo p -= 1 array[p] = current_element + + +Merge Sort +============== + +Como o algoritmo funciona: Como implementar o algoritmo usando Python: `https://www.youtube.com/watch?v=Lnww0ibU0XM `_. + +.. youtube:: Lnww0ibU0XM + + +Como implementar o algoritmo usando Python - Parte I: `https://www.youtube.com/watch?v=cXJHETlYyVk `_. + +.. youtube:: cXJHETlYyVk + +Código do algoritmo + +.. code-block:: python + + def sort(array): + sort_half(array, 0, len(array) - 1) + + + def sort_half(array, start, end): + if start >= end: + return + + middle = (start + end) // 2 + + sort_half(array, start, middle) + sort_half(array, middle + 1, end) + + merge(array, start, end) + + + def merge(array, start, end): + array[start: end + 1] = sorted(array[start: end + 1]) +