Skip to content

Commit 8a4925b

Browse files
committed
Add Python Comb Sort & Add link to Python Heap Sort on README
1 parent 0be3341 commit 8a4925b

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2696,8 +2696,8 @@ Com o objetivo de alcançar uma abrangência maior e encorajar novas pessoas a c
26962696
</a>
26972697
</td>
26982698
<td> <!-- Python -->
2699-
<a href="./CONTRIBUTING.md">
2700-
<img align="center" height="25" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/github/github-original.svg" />
2699+
<a href="./src/python/comb_sort.py">
2700+
<img align="center" height="25" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/python/python-original.svg" />
27012701
</a>
27022702
</td>
27032703
<td> <!-- Go -->
@@ -2870,8 +2870,8 @@ Com o objetivo de alcançar uma abrangência maior e encorajar novas pessoas a c
28702870
</a>
28712871
</td>
28722872
<td> <!-- Python -->
2873-
<a href="./CONTRIBUTING.md">
2874-
<img align="center" height="25" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/github/github-original.svg" />
2873+
<a href="./src/python/heap_sort.py">
2874+
<img align="center" height="25" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/python/python-original.svg" />
28752875
</a>
28762876
</td>
28772877
<td> <!-- Go -->

src/python/comb_sort.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
#----------------------------------------------------------------------------
4+
# Created By : octaviolage
5+
# Created Date: 2022-05-15
6+
# version ='1.0'
7+
# -------------------------------
8+
def comb_sort(arr: list) -> list:
9+
"""
10+
Implementação de um algoritmo de ordenação combinada.
11+
"""
12+
gap = len(arr)
13+
shrink = 1.3
14+
swapped = True
15+
while gap > 1 or swapped:
16+
gap = int(gap / shrink)
17+
if gap < 1:
18+
gap = 1
19+
swapped = False
20+
for i in range(len(arr) - gap):
21+
if arr[i] > arr[i + gap]:
22+
arr[i], arr[i + gap] = arr[i + gap], arr[i]
23+
swapped = True
24+
return arr
25+
26+
if __name__ == '__main__':
27+
from random import randint
28+
my_list = [randint(0, 100) for _ in range(10)]
29+
print(f'Lista: {my_list}')
30+
print(f'Ordenada: {comb_sort(my_list)}')

0 commit comments

Comments
 (0)