//Bubble sort algorithm implementation. Also calculate time complexity.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],temp,i,j,n,count;
count=0;count++;
printf("Bubble Sort
Enter total no. of values: ");
{
scanf("%d",&n);
count++;
}
printf("Enter the values:-
");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
count++;
}
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
if(a[j]<a[i])
{
temp=a[j];count++;
a[j]=a[i];count++;
a[i]=temp;count++;
}
count++;
}
count++;
}
printf("Bubble-Sort result:-
");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
count++;
}
printf("
Time Complexity is: %d",count);
getch();
}
//program written by Mars.
0 comments:
Post a Comment