Bubble Sort in C

Here you will learn about program for bubble sort in C.

Bubble sort is a simple sorting algorithm in which each element is compared with adjacent element and swapped if their position is incorrect. It is named as bubble sort because same as like bubbles the lighter elements come up and heavier elements settle down.

Both worst case and average case complexity is O (n2).

Bubble Sort in C

 

Output

Enter the size of array: 4
Enter the array elements: 3 7 9 2

Array after sorting: 2 3 7 9

 

Comment below if you have any doubts related to above program for bubble sort in C.

9 thoughts on “Bubble Sort in C

  1. Ajay shankhwar

    Why we use return 0 ?
    If we will not use it.what changes may occur in program?

    Reply
    1. Tushar shende

      We have write the written type of main as “int” so at last it should write something value ,,,so the return 0 is written.

      If u use written type of main as “void main” then “getch()” will work fine

      Reply
  2. Adlin

    Can you help me sir? i dont know how to do it

    1. Develop a program that can sort number up to 100 000 number using bubble sort algorithm
    and calculate their complexity for BEST CASE scenario. The program should follow the
    guidelines below:
    i) The program will generate 100 000 number from 1 until 100 000 in ascending order,
    and display all the numbers. All the numbers will be stored in one array.
    ii) The program will sort the number section by section start from the first 10 000
    numbers, then the first 20 000 numbers, then the first 30 000 numbers, until all the
    100 000 numbers sorted. Use function looping for these operations.
    iii) For each section, calculate time complexity in seconds, total number of comparison,
    and total number of steps for the algorithm needed to solve the sorting problem.
    iv) Lastly generate graph of time complexity, total number of comparison, and total
    number of steps versus total of number to be sorted.

    Reply

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.