Skip to content

Commit

Permalink
daily commit 2024-05-05
Browse files Browse the repository at this point in the history
  • Loading branch information
chirbard committed May 5, 2024
1 parent 6a9b366 commit 86cb5e5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions 2024-05-05/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Codecademy bubble sort implementation
This is a bubble sort implementation in Codecademy "Learn Data Structures and Algorithms with Python" course.

Link to course: https://www.codecademy.com/enrolled/courses/learn-data-structures-and-algorithms-with-python
20 changes: 20 additions & 0 deletions 2024-05-05/bubble_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
nums = [5, 2, 9, 1, 5, 6]

def swap(arr, index_1, index_2):
temp = arr[index_1]
arr[index_1] = arr[index_2]
arr[index_2] = temp

# define bubble_sort():
def bubble_sort(arr):
for el in arr:
for i in range(len(arr) - 1):
if arr[i] > arr[i + 1]:
swap(arr, i, i + 1)


##### test statements

print("Pre-Sort: {0}".format(nums))
bubble_sort(nums)
print("Post-Sort: {0}".format(nums))

0 comments on commit 86cb5e5

Please sign in to comment.