F How to implement bubble sort in array? [C] | CodeTheta

How to implement bubble sort in array? [C]


Here you can see a bubble sort programming code which is written in c programming.it is a most popular sort in data structure. in this code you can see the array is defined .the array which is defined in the code is a static array mean its size is fixed after that we have defined four variable and one of them is temp whose job is store the variable for temporarily.

Source Code :

/*
  Program to implement BUBLE SORTING in Array.
  http://www.codetheta.com
  --------------------------------------------
*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,j,k,temp;
clrscr();
printf("\n Enter the values of Array A -> \n");
for(i=0;i<10;i++)
   scanf("%d",&a[i]);
//Sorting
for(i=0;i<9;i++)
   for(j=0;j<9-i;j++)
      {
      printf("\n i=%d , j=%d -> ",i+1,j+1);
      for(k=0;k<10;k++)
         printf("%d  ",a[k]);
      if(a[j+1]<a[j])
        {
        temp=a[j+1];
        a[j+1]=a[j];
        a[j]=temp;
        }
      }
printf("\n The sorted array is -> ");
for(i=0;i<10;i++)
   printf("%d  ",a[i]);
getch();
}

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.

Post a Comment