-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram8.c
67 lines (66 loc) · 950 Bytes
/
program8.c
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
67
#include<stdio.h>
#include<conio.h>
#include<time.h>
#include<windows.h>
#include<stdlib.h>
void split(int a[],int low,int high)
{
int mid;
if(low<high)
{
mid=(low+high)/2;
split(a,low,mid);
split(a,mid+1,high);
mergesort(a,low,mid,high);
}
}
void mergesort(int a[],int low,int mid,int high){
int i,j,k,c[10000];
i=low;
j=mid+1;
k=low;
while(i<=mid && j<=high){
if(a[i]<a[j]){
c[k]=a[i];
i=i+1;
k=k+1;
}
else{
c[k]=a[j];
j=j+1;
k=k+1;
}
}
if(j>high){
while(i<=mid){
c[k]=a[i];
k=k+1;
i=i+1;
}
}
if(i>mid){
while(j<=high){
c[k]=a[j];
k=k+1;
j=j+1;
}
}
}
void main ()
{
int a[10000],i,j,k,n;
clock_t s,e;
printf("Merge sort\n");
n=1000;
while(n<10000){
for(i=0;i<n;i++){
a[i]=n-i;
}
s=clock();
split(a,0,n-1);
Sleep(150);
e=clock();
printf("\nTime taken for Merge sort where n : %d is: %f\n",n,((double)(e-s))/CLK_TCK);
n=n+1000;
}
}