-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBubbleSort.py
36 lines (28 loc) · 831 Bytes
/
BubbleSort.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#User function Template for python3
class Solution:
#Function to sort the array using bubble sort algorithm.
def bubbleSort(self,arr, n):
for i in range(n-1,0,-1):
didSwap = 0
for j in range(i):
if arr[j] > arr[j+1]:
temp = arr[j+1]
arr[j+1] = arr[j]
arr[j] = temp
didSwap = 1
if didSwap == 0:
break
#{
# Driver Code Starts
#Initial Template for Python 3
if __name__=='__main__':
t = int(input())
for i in range(t):
n = int(input())
arr = list(map(int, input().strip().split()))
ob = Solution()
ob.bubbleSort(arr, n)
for i in arr:
print(i,end=' ')
print()
# } Driver Code Ends