EmbLogic's Blog

bubble sort with less complexity than O(n2)

#include
main()
{
int n=10;
int a[10]={89,22,20,2,11,39,32,21,87,98},swap=1,j,i,temp;
printf(“this is a bubble sorting technique\n”);
for(i=0;i<n&&swap==1;i++)
{
swap=0;
for(j=0;j=a[j+1])
{
swap=1;
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
else
printf(“element sorted\n”);
}
}
for(i=0;i<n;i++)
{
printf("a[%d]=%d\n",i,a[i]);
}
return 0;
}

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>