|
1 | 1 | Algoritmos de Ordenação |
2 | 2 | ######################## |
3 | 3 |
|
4 | | -:date: 2018-11-20 23:10 |
| 4 | +:date: 2018-11-29 13:10 |
5 | 5 | :tags: python, algoritmos |
6 | 6 | :category: Python |
7 | 7 | :slug: algoritmos-ordenacao |
@@ -48,12 +48,11 @@ Código do algoritmo |
48 | 48 | Selection Sort |
49 | 49 | ============== |
50 | 50 |
|
51 | | -Como o algoritmo funciona: Como implementar o algoritmo usando Python: `https://www.youtube.com/watch?v=PLvo_Yb_myrNBhIdq8qqtNSDFtnBfsKL2r <https://www.youtube.com/watch?v=PLvo_Yb_myrNBhIdq8qqtNSDFtnBfsKL2r&list=PLvo_Yb_myrNBhIdq8qqtNSDFtnBfsKL2r&t=0s&index=4>`_. |
| 51 | +Como o algoritmo funciona: Como implementar o algoritmo usando Python: `https://www.youtube.com/watch?v=vHxtP9BC-AA <https://www.youtube.com/watch?v=vHxtP9BC-AA&list=PLvo_Yb_myrNBhIdq8qqtNSDFtnBfsKL2r&index=4>`_. |
52 | 52 |
|
| 53 | +.. youtube:: vHxtP9BC-AA |
53 | 54 |
|
54 | | -.. youtube:: PLvo_Yb_myrNBhIdq8qqtNSDFtnBfsKL2r |
55 | | - |
56 | | -Como implementar o algoritmo usando Python: `https://www.youtube.com/watch?v=0ORfCwwhF_I <https://www.youtube.com/watch?v=0ORfCwwhF_I&index=5&list=PLvo_Yb_myrNBhIdq8qqtNSDFtnBfsKL2r>`_. |
| 55 | +Como implementar o algoritmo usando Python: `https://www.youtube.com/watch?v=0ORfCwwhF_I <https://www.youtube.com/watch?v=0ORfCwwhF_I&index=5&list=PLvo_Yb_myrNBhIdq8qqtNSDFtnBfsKL2r&index=5>`_. |
57 | 56 |
|
58 | 57 | .. youtube:: 0ORfCwwhF_I |
59 | 58 |
|
@@ -96,3 +95,40 @@ Código do algoritmo |
96 | 95 | p -= 1 |
97 | 96 |
|
98 | 97 | array[p] = current_element |
| 98 | +
|
| 99 | +
|
| 100 | +Merge Sort |
| 101 | +============== |
| 102 | + |
| 103 | +Como o algoritmo funciona: Como implementar o algoritmo usando Python: `https://www.youtube.com/watch?v=Lnww0ibU0XM <https://www.youtube.com/watch?v=Lnww0ibU0XM&list=PLvo_Yb_myrNBhIdq8qqtNSDFtnBfsKL2r&t=0s&index=8>`_. |
| 104 | + |
| 105 | +.. youtube:: Lnww0ibU0XM |
| 106 | + |
| 107 | + |
| 108 | +Como implementar o algoritmo usando Python - Parte I: `https://www.youtube.com/watch?v=cXJHETlYyVk <https://www.youtube.com/watch?v=cXJHETlYyVk&index=9&list=PLvo_Yb_myrNBhIdq8qqtNSDFtnBfsKL2r>`_. |
| 109 | + |
| 110 | +.. youtube:: cXJHETlYyVk |
| 111 | + |
| 112 | +Código do algoritmo |
| 113 | + |
| 114 | +.. code-block:: python |
| 115 | +
|
| 116 | + def sort(array): |
| 117 | + sort_half(array, 0, len(array) - 1) |
| 118 | +
|
| 119 | +
|
| 120 | + def sort_half(array, start, end): |
| 121 | + if start >= end: |
| 122 | + return |
| 123 | +
|
| 124 | + middle = (start + end) // 2 |
| 125 | +
|
| 126 | + sort_half(array, start, middle) |
| 127 | + sort_half(array, middle + 1, end) |
| 128 | +
|
| 129 | + merge(array, start, end) |
| 130 | +
|
| 131 | +
|
| 132 | + def merge(array, start, end): |
| 133 | + array[start: end + 1] = sorted(array[start: end + 1]) |
| 134 | +
|
0 commit comments