Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Bubble Sort [py] #866

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions bubble_sort/bubble_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
def bubble_sort(arr):
"""
Performs a bubble sort
: type arr: int
"""
for index_1 in range(len(arr)):
for index_2 in range(0,len(arr)-index_1-1):
if (arr[index_2]>arr[index_2+1]):
temp=arr[index_2+1]
arr[index_2+1]=arr[index_2]
arr[index_2]=temp


def main():
arr = [2, 3, 0, 4,-4,56,12]
print("Before Sorting")
bubble_sort(arr)
print(arr)


if __name__ == '__main__':
main()