Bubble Sort in C

Bubble Sort

Here, You will learn Bubble sort Algorithm and get the program code of Bubble Sort in C programming. Bubble sort is a sorting algorithm concept from the Data Structure.

What is Sorting?

Sorting is a technique of rearranging the elements in any particular order. It might be in either ascending or descending sequence.

 

Describe Bubble sort algorithm with example

Bubble sort is an algorithm for sorting a list of elements. It compares nearby components and swaps them if they are not in the correct sequence. This step is continued until the list is sorted.
Example:

Input list: 4, 2, 8, 6, 1

Step 1: Compare 4 and 2, since 4 is greater than 2, swap them. List is now 2, 4, 8, 6, 1

Step 2: Compare 4 and 8, since 4 is less than 8, no swap needed.

Step 3: Compare 8 and 6, since 8 is greater than 6, swap them. List is now 2, 4, 6, 8, 1

Step 4: Compare 8 and 1, since 8 is greater than 1, swap them. List is now 2, 4, 6, 1, 8

Step 5: List is sorted, no more swaps needed.

Sorted list: 1, 2, 4, 6, 8

 

Bubble Sort in C Program

Input

Enter The Limit :6

Enter array Elements :

2

5

3

7

6

1

Output

The Sorted Elements :

1

2

3

5

6

7

 


 

Read Also

Quick Sort

Counting Sort

Bucket Sort

Radix Sort

 

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top