In [1]:
import array as arr
def BubbleSort(A, n):
for i in range(0, n):
check = 0
for j in range(0, n - i - 1):
if A[j] > A[j + 1]:
temp = A[j]
A[j] = A[j + 1]
A[j + 1] = temp
check = 1
if check == 0:
break
print ('Sorted array is: ')
for i in range (0, n):
print (A[i], end = ',')
s = int (input ('Enter the size of the array: '))
print('Enter the lements of the array: ')
A = arr.array('i', [])
for i in range(0, s):
element = int (input())
A.append(element)
BubbleSort(A, s)
Enter the size of the array: 5 Enter the lements of the array: 10 1 2 20 5 Sorted array is: 1,2,5,10,20,
No comments:
Post a Comment