//this code is designed by codenation.
//5:25 22/11/2020
#include<stdio.h>
int main()
{
int N,i,ptr,temp=0,swap=0;
printf("enter the size of array : \n");
scanf("%d",&N);
int data[N],comp=0;
printf("enter the set of data :\n");
for(i=0;i<N;i++)
{
printf("enter the %d element : \n",i+1);
scanf("%d",&data[i]);
}
for(i=0;i<N-1;i++)
{
ptr=0;
for(ptr=0;ptr<=N-2-i;ptr++)
{
comp++;
if(data[ptr]>data[ptr+1])
{
temp=data[ptr];
data[ptr]=data[ptr+1];
data[ptr+1]=temp;
swap=1;
}
}
if(swap==0)
{
break;
}
}
printf("the no of comparisons are :%d\n",comp);
printf("the sorted set in ascending order is :\n");
for(i=0;i<N;i++)
{
printf("%d\n",data[i]);
}
}
//this code is developed by codenation.
Comments
Post a Comment