Sorting of an array using Bubble sorting
Bubble sort is a simple sorting algorithm. This sorting algorithm is comparison-based algorithm in which each pair of adjacent elements is compared and the elements are swapped if they are not in order. This algorithm is not suitable for large data sets as its average and worst case complexity are of O(n2) where n is the number of items.
Suppose we are trying to sort the elements in ascending order.
The same process goes on for the remaining iterations.
After each iteration, the largest element among the unsorted elements is placed at the end.
In each iteration, the comparison takes place up to the last unsorted element.
The array is sorted when all the unsorted elements are placed at their correct positions.
Enter an array:
For example if array is [1,2,3,4]
simply enter 1,2,3,4
Here's the result
array= eval(input("Enter the array for sorting: "))
def bSort(array):
for i in range(len(array)):
for j in range(len(array)-i-1):
if(array[j]> array[j+1]):
hey= array[j]
array[j]= array[j+1]
array[j+1]= hey
print(array)
bSort(array)
print(array)
Hence we can perform sorting of arrays using Bubble sorting.
Mr. Nilesh Pandey, B.Sc(H) Computer Science, II year,
Ms. Ananya Shukla, B.Sc(H) Computer Science, II year,
Mr. Amitesh Kumar Singh, B.Sc(H) Computer Science, II year.
Mentors:
Prof. Sharanjit Kaur,
Ms. Nishu Singh