Saturday, May 18, 2019

Bubble sort - C Program and Algorithm - Data Structures



For many other Language Programs related to microprocessor 8086, data structures  and C++ visit our  BLOG 


Algorithm:

1. start
2. repeate step 3 for i= 0 to n-1
3. repeate for j=0 to n-1
4. if a[j]= a[j+1] then swap a[j[ and a[j+1]
5. exit

Program :
#include<stdio.h>
#include<conio.h>
void main()
{
int a[25],temp,n,i,j;
clrscr();
printf(“enter array size”);
scanf(“%d”,&n);
printf(“enter array data”);
for(i=0;i<n;i++)
scanf(“%d”,&a[i]);
for(i=0;i<n;i++)
{
for(j=0;j<n-1;i++)
{
if(a[j]>a[j+1])
{
temp = a[j];
a[j] =a[j+1];
a[j+1] =temp;
}
}
}
printf(“\n\nafter sort :- ”);
for(i=0;i<n;i++)
printf(“\n %d”,a[i]);
getch();
}
For many other Language Programs related to microprocessor 8086 ,C++ , data structures visit our  BLOG 

There are programs of bubble , selection , linear search , pop, push ,etc for data structures


No comments:

Post a Comment