Bubble sort in C

In this post, let’s see how to implement bubble sort in C.

Bubble sort, also known as sinking sort,compares adjacent elements and swap them if they are not in correct order.
Here is a simple illustration of bubble sort.

Bubble sort

Above GIF is generated from algorithms app.

Output:

Array before sorting: 67 23 45 74 12 34
Array after sorting: 12 23 34 45 67 74

Both worst case and average case complexity is O (n^2) for bubble sort.

Was this post helpful?

Leave a Reply

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