Bubble Sort in C

Advertisements

Sortin in C Selection Sort in C

Bubble Sort Program in C

Bubble sort is the simplest sorting algorithm. In this technique we follow given step to short given elements in increasing order.

Steps to Sort data

  • First compare First (previous) element with its next elements.
  • If next element is grater than previous element just ignore it.
  • If next element is smaller than previous element then interchange their position.
bubble sort in c

Advantage of Bubble short

It is very simple and easy method to short elements.

Dis-Advantage of Bubble short

It is time comsuming and slow process to short elements.

Bubble Sort Program in C

	
#include<stdio.h>
#include<conio.h>
#include<dos.h>

void main()
{
int i,a[100],temp,j,no;
clrscr();
printf("How many no. do u want to insert: ");
scanf("%d",&no);
printf("\nEnter any %d num in array \n",no);

for(i=0;i<no;i++)
{
scanf("%d",&a[i]);
}
printf("\n\n\nData before sorting : ");
for(j=0;j<no;j++)
{
delay(200);
printf("  %d",a[j]);
}
for(i=0;i<no;i++)
{
for(j=0;j<no-i-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("\n\n\nData after sorting : ");
for(j=0;j<no;j++)
{
delay(200);
printf("  %d",a[j]);
}
getch();
}

Output

	
How many no. do u want to insert: 8
Enter any 8  num in array
Data before sorting : 5 3 6 2 7 8 1 4 
Data after sorting : 1 2 3 4 5 6 7 8
sort elements
Sorting in C Selection Sort in C

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements