forked from Abhijeet5665/c-programs-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting.c
More file actions
66 lines (49 loc) · 846 Bytes
/
testing.c
File metadata and controls
66 lines (49 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void merge(int a[],int low,int mid,int high){
int b[10000000],i,j,k;
for(i=low;i<=high;i++)
b[i]=a[i];
i=low;
j=mid+1;
k=low;
while(i<=mid && j<=high)
{
if(b[i]<b[j])
a[k++]=b[i++];
else
a[k++]=b[j++];
}
while(i<=mid)
a[k++]=b[i++];
while(j<=high)
a[k++]=b[j++];
}
void mergesort(int a[],int low,int high){
int mid;
if(low<high){
mid=(low+high)/2;
mergesort(a,low,mid);
mergesort(a,mid+1,high);
merge(a,low,mid,high);
}
}
void main(){
int n;
clock_t start,end;
printf("Eneter the array size\n");
scanf("%d",&n);
int a[n],i;
printf("enetre the elemnts\n");
for(i=n;i>0;i--)
a[n-i]=i;
start=clock();
mergesort(a,0,n-1);
end=clock();
for(i=0;i<n;i++)
printf("%d ",a[i]);
printf("-----------------------\n");
float time=(float)(end-start)/CLOCKS_PER_SEC;
printf("%f\n",time);
}