#-------------------------------- Bubble Sort using for loop -----------------------------
count =0 # initializing count as 0
array = [] #initializing empty array
n = int(input("Enter the no. of elements : ")) # total no. of elements in the list
# getting inputs from user
for i in range(n):
print(i+1,end=".")
nums = int(input("Enter the number : ")) # gets the value one by one
array.append(nums) # add element at the end of the array
for i in range(n):
for j in range(0, n - i - 1):
# if the element found Swap the elements
if array[j] > array[j + 1]:
array[j], array[j + 1] = array[j + 1], array[j]
count+=1
print("Sorted Array")
print(array)
print("iterated for ",count,"times")
#-------------------------------- Bubble Sort using while loop -----------------------------
count =0 # initializing count as 0
array = [] #initializing empty array
n = int(input("Enter the no. of elements : ")) # total no. of elements in the list
# getting inputs from user
for m in range(n):
print(m+1,end=".")
nums = int(input("Enter the number : ")) # gets the value one by one
array.append(nums) # add element at the end of the array
i = 0
while (i < n):
j = 0
while (j < n - i - 1):
# if the element found is greater Swap
if (array[j] > array[j + 1]):
array[j], array[j + 1] = array[j + 1], array[j]
j += 1
i += 1
count+=1
print("Sorted elements : ",array)
print("\nIterated for",count,"times")
#-------------------------------- Bubble Sort using without dupliate ------------------------
count =0 # initializing count as 0
array = [] #initializing empty array
n = int(input("Enter the no. of elements : ")) # total no. of elements in the list
# getting inputs from user
for m in range(n):
print(m+1,end=".")
nums = int(input("Enter the number : ")) # gets the value one by one
array.append(nums) # add element at the end of the array
i = 0
while (i < n):
j = 0
while (j < n - i - 1):
if array[j] == array[j+1]:
array.pop(i)
if ( array[j] > array[j + 1] ):
array[j], array[j + 1] = array[j + 1], array[j]
j += 1
i += 1
count+=1
print("Sorted elements : ",array)
print("\nIterated for",count,"times")