Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5b43325

Browse filesBrowse files
authored
Merge pull request #15 from Abhishek-Jain-2/patch-2
Create BubbleSort.py
2 parents 6b10c14 + cd6a002 commit 5b43325
Copy full SHA for 5b43325

File tree

Expand file treeCollapse file tree

1 file changed

+26
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+26
-0
lines changed

‎BubbleSort.py

Copy file name to clipboard
+26Lines changed: 26 additions & 0 deletions
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-1):
8+
# range(n) also work but outer loop will repeat one time more than needed.
9+
10+
# Last i elements are already in place
11+
for j in range(0, n-i-1):
12+
13+
# traverse the array from 0 to n-i-1
14+
# Swap if the element found is greater
15+
# than the next element
16+
if arr[j] > arr[j+1] :
17+
arr[j], arr[j+1] = arr[j+1], arr[j]
18+
19+
# Driver code to test above
20+
arr = [64, 34, 25, 12, 22, 11, 90]
21+
22+
bubbleSort(arr)
23+
24+
print ("Sorted array is:")
25+
for i in range(len(arr)):
26+
print ("%d" %arr[i]),

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.