Skip to content

Commit 0ac8776

Browse files
committed
BubbleSort
1 parent 12ee87b commit 0ac8776

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Sorting-Python-Code/bubbleSort.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Bubble sort defination
2+
"""
3+
Repeatedly swap two adjacent element if they are in wrong order
4+
5+
"""
6+
#Condition L>R (wrong order ) & needs Swap
7+
"""
8+
in Every Loop Iteration decrease -1
9+
1st iteration n-1
10+
2nd iteration n-2
11+
3rd iteration n-3
12+
i th iteration n-i
13+
14+
but in python n-1 b'coz using of len function
15+
16+
"""
17+
18+
'''
19+
hdiusiu
20+
'''
21+
def bubblesort(arr):
22+
n=len(arr)
23+
for i in range(n-1):
24+
for j in range(0,n-i-1):
25+
if arr[j]>arr[j+1]:
26+
arr[j],arr[j+1]=arr[j+1],arr[j]
27+
28+
29+
arr=[12,22,12,23,332,12,33]
30+
bubblesort(arr)
31+
print(arr)

0 commit comments

Comments
 (0)