Bubble Sort With Time Complexity In C

#include<stdio.h>
#include<time.h>
#define CLOCK_PER_SEC 1000;
long int data[50000];
int main(){
	
	long int n=50000,i,j,temp,value;
	double end;
	clock_t start;
	FILE *fp;
	FILE *fpl;
	fp=fopen("Documentinput.txt","r");
	fpl=fopen("output.txt","a");
	fscanf(fp,"%d",&n);
	printf("Read Data from file \n");
	for(i=1;i<=n;i++){
		fscanf(fp,"%d",&data[i]);
	}
	printf("Data reading completed\n");
	printf("Data sorting started........\n");
	start=clock();

	for(i=1;i<n;i++)
	{
		for(j=1;j<n-i-1;j++){
			if(data[j]>data[j+1]){
				temp=data[j];
				data[j]=data[j+1];
				data[j+1]=temp;
			}
		}
	}

	end=((double)clock()-start)/CLOCK_PER_SEC;
	printf("Data sorting completed\n");
	printf("No. of Data......|......Time needed for searching\n");
	printf("%d\t\t\t %lf",n,end);
	printf("This information is added to file 'output.txt'\n");
	fprintf(fpl,"%d %lf",n,end); 
		
}

Hits: 8

S M Mohaimanul Islam

Mad man loving technology.

Leave a Reply

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