Commit 78937d80 authored by KONDETI TANMAYEE's avatar KONDETI TANMAYEE

Upload new file

parent 297723e8
#include<iostream>
#include<stdlib.h>
using namespace std;
void insertionSort(int *a,int n) {
for(int i=0;i<n-1;i++) {
for(int j=i+1;j<n;j++) {
if(a[i]>a[j]) swap(a[i],a[j]);
}
}
}
int main() {
int a[1000],step=10;
double clocksPerMillis=double(CLOCKS_PER_SEC)/1000;
for(int n=0;n<=1000;n+=step) {
int rep;
clock_t startTime=clock();
do {
rep++;
for(int i=0;i<n;i++) {
a[i]=rand() % n + 1;
}
insertionSort(a,n);
}while(rep<=20);
double elapsedMillis=(clock()-startTime)/clocksPerMillis;
cout<<n<<'\t'<<elapsedMillis/rep<<endl;
if(n==100) step=100;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment