Skip to content

Commit d313632

Browse files
authored
Create BubbleSort.py
Added code bubble sort
1 parent f298d1a commit d313632

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

BubbleSort.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def bubbleSort(ar):
2+
n = len(arr)
3+
# Traverse through all array elements
4+
for i in range(n):
5+
# Last i elements are already in correct position
6+
for j in range(0, n-i-1):
7+
# Swap if the element found is greater than the next element
8+
if ar[j] > ar[j+1] :
9+
ar[j], ar[j+1] = ar[j+1], ar[j]
10+
# Driver code to test above
11+
ar = ['t','u','t','o','r','i','a','l']
12+
bubbleSort(ar)
13+
print ("Sorted array is:")
14+
for i in range(len(ar)):
15+
print (ar[i])

0 commit comments

Comments
 (0)