Science, asked by arunrgs7779, 1 year ago

Write a C program to print the time complexity of bubble sort?

Answers

Answered by rjkgupta927pefr2q
0
//PROGRAM TO CALCULATE BUBBLE SORT

#include<stdio.h>

#include<time.h>

void main()

{

clock_t start_t,end_t;

float total_t;

FILE *fr;

int i=0,j=0,a[50000],x,temp;

fr=fopen("new.txt","w");

for(i=0;i<50000;i++)

{

x=rand()%50000;

fprintf(fr,"%d\n",x);

}

fclose(fr);

fr=fopen("new.txt","r");

if(fr==NULL)

{

printf("File is empty");

}

else

{

for(i=0;i<50000;i++)

{

fscanf(fr,"%d",&a[j]);

j++;

}

}

close(fr);

start_t=clock();

for(i=0;i<50000-1;i++)

{

for(j=0;j<50000-1-i;j++)

{

if(a[j]>a[j+1])

{

temp=a[j];

a[j]=a[j+1];

a[j+1]=temp;

}

}

}

end_t=clock();

printf("start_t= %ld\n", start_t);

printf("end_t= %ld\n", end_t);

printf("clock per sec= %ld\n",CLOCKS_PER_SEC);

total_t=(end_t - start_t);

printf("total time= %f",total_t/CLOCKS_PER_SEC);

fr=fopen("sort.txt","w");

for(i=0;i<50000;i++)

{

fprintf(fr,"%d ",a[i])

Answered by hkrista208
0

Answer:i need help with money to get a big enough place for my family

Explanation:

Dafax took my babies from me and i need help getting them back

Similar questions