Skip to content

Commit

Permalink
feat(sorts): add bubble sort for beginners with doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
laysaalves committed Oct 1, 2024
1 parent ea06a9b commit f214a0f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions sorts/simple_bubble_sort.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from typing import List


def bubble_sort(nums: List[int]) -> List[int]:
def bubble_sort(nums: list[int]) -> list[int]:
"""
param nums: the array of integers(int) because this application does not use decimal numbers, but if needed, use float type.

Check failure on line 3 in sorts/simple_bubble_sort.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

sorts/simple_bubble_sort.py:3:89: E501 Line too long (128 > 88)

Check failure on line 3 in sorts/simple_bubble_sort.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

sorts/simple_bubble_sort.py:3:89: E501 Line too long (128 > 88)

Check failure on line 3 in sorts/simple_bubble_sort.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

sorts/simple_bubble_sort.py:3:89: E501 Line too long (128 > 88)
:return: the same nums List ordered by ascending
:return: the same nums list ordered by ascending
Examples:
>>> bubble_sort([8, 2, 4, 5, 7, 0])
[0, 2, 4, 5, 7, 8]
step 01: create the nums array
step 02: collect the dimension of array
Expand All @@ -21,7 +22,10 @@ def bubble_sort(nums: List[int]) -> List[int]:
nums[j], nums[j + 1] = nums[j + 1], nums[j]
return nums


nums = [65, 66, 12, 4, 9, 10, 32, 2] # 01
ordered_nums = bubble_sort(nums) # 06
print("The result:", ordered_nums)

if __name__ == "__main__":
import doctest
doctest.testmod()

Check failure on line 31 in sorts/simple_bubble_sort.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W292)

sorts/simple_bubble_sort.py:31:22: W292 No newline at end of file

Check failure on line 31 in sorts/simple_bubble_sort.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W292)

sorts/simple_bubble_sort.py:31:22: W292 No newline at end of file

Check failure on line 31 in sorts/simple_bubble_sort.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W292)

sorts/simple_bubble_sort.py:31:22: W292 No newline at end of file

0 comments on commit f214a0f

Please sign in to comment.