Skip to content

Commit dfdb312

Browse files
Merge pull request #21 from ashishkrishan1995/master
bubblesort using python
2 parents cf0e0ed + 6bec965 commit dfdb312

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Code/bubbleSort.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Python program for implementation of Bubble Sort
2+
3+
def bubbleSort(arr):
4+
n = len(arr)
5+
6+
# Traverse through all array elements
7+
for i in range(n):
8+
9+
# Last i elements are already in place
10+
for j in range(0, n-i-1):
11+
12+
# traverse the array from 0 to n-i-1
13+
# Swap if the element found is greater
14+
# than the next element
15+
if arr[j] > arr[j+1] :
16+
arr[j], arr[j+1] = arr[j+1], arr[j]
17+
18+
# Driver code to test above
19+
arr = [64, 34, 25, 12, 22, 11, 90]
20+
21+
bubbleSort(arr)
22+
23+
print ("Sorted array is:")
24+
for i in range(len(arr)):
25+
print ("%d" %arr[i]),

0 commit comments

Comments
 (0)