Bubble sort program in C using array with examples

There are many techniques to sort the values. Bubble sort is one of the sorting algorithm used to sort the values in effective way.Bubble sort is compare the values of adjacent elements repeatedly and then swapping their position if they exist in the wrong order.

Bubble sort Algorithm : How it works

1.The unsorted array of 5 elements given as input to bubble sort.It will compare the first and second element to check which one is greater and swap the elements if first element is greater than the second element.

2.Compare the second and third element to check which one is greater and swap the element if the second element is greater than third element.

3.Compare the third and fourth element to check which one is greater and swap the element if the third element is greater than fourth element.

4.Compare the fourth and fifth element to check which one is greater and swap the element if the fourth element is greater than fifth element.

5.Repeat steps 1-5 until no more swaps are required.

Example of Bubble sort

Input values in unsorted order:
5
4
3
2
1

Bubble Sort Alogorithm

Implementation:

Output: