Skip to content

Commit 277bcb1

Browse files
authored
Merge pull request argonautica#47 from PonderfulWoop/master
Added BubbleSort.py
2 parents 7dc76e6 + 69b740f commit 277bcb1

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Python/BubbleSort.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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]),
26+

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ _Sorting algorithms implemented in different languages (for hacktoberfest 😃).
5050

5151
### Python
5252
- [Bogo Sort](Python/BogoSort.py)
53+
- [Bubble Sort](Python/BubbleSort.py)
5354
- [Bucket Sort](Python/BucketSort.py)
5455
- [Gnome Sort](Python/GnomeSort.py)
5556
- [Insertion Sort](Python/InsertionSort.py)

0 commit comments

Comments
 (0)