Skip to content
Open
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
28 changes: 28 additions & 0 deletions Bubble_Sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

@@ -0,0 +1,26 @@
# Python3 program for Bubble Sort Algorithm Implementation
def bubbleSort(arr):

n = len(arr)

# For loop to traverse through all
# element in an array
for i in range(n):
for j in range(0, n - i - 1):

# Range of the array is from 0 to n-i-1
# Swap the elements if the element found
#is greater than the adjacent element
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]

# Driver code

# Example to test the above code
arr = [ 2, 1, 10, 23 ]

bubbleSort(arr)

print("Sorted array is:")
for i in range(len(arr)):
print("%d" % arr[i])