Skip to content

Commit 220d6c0

Browse files
committed
Update BubbleSort.py
1 parent b370a01 commit 220d6c0

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed
Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
#this is the most easiest algorith which jst involves swapping of elements
2-
import array
3-
def BubbleSort(a):
4-
n = len(a)
5-
6-
for i in range(n):
7-
for j in range(i+1 , n):
8-
if(a[i]>a[j]):
9-
a[i] , a[j] = a[j] , a[i]
10-
11-
a = array.array('i' , [])
12-
13-
n = int(input("Enter lenght of array : "))
14-
15-
for i in range(n):
16-
c = int(input("Enter the number : "))
17-
a.append(c)
18-
19-
BubbleSort(a)
20-
print(list(a))
1+
def bubbleSort(lst):
2+
n = len(lst)
3+
4+
for i in range(n-1):
5+
6+
for j in range(0, n-i-1):
7+
8+
9+
if lst[j] > lst[j + 1] :
10+
lst[j], lst[j + 1] = lst[j + 1], lst[j]
11+
12+
lst = [64, 34, 25, 12, 22, 11, 90]
13+
14+
bubbleSort(lst)

0 commit comments

Comments
 (0)