-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerge.h
More file actions
41 lines (35 loc) · 907 Bytes
/
merge.h
File metadata and controls
41 lines (35 loc) · 907 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
#ifndef _MERGEH_
#define _MERGEH_
//compare function for qsort() to be used in multisort()
int compare_function(const void *a, const void *b)
{
return (*(int *)a - *(int *)b );
}
void merge(int *X, int *X_size, int *temp, int *temp_size, int *result)
{
int i = 0;
while(X <= X_size && temp <= temp_size)
{
if((*X) < (*temp))
{
result[i++] = *X;
X++;
}
else
{
result[i++] = *temp;
temp++;
}
}
while (X <= X_size) //finishing up the lower half
{
result[i++] = *X;
X++;
}
while (j<N) //finishing up the upper half
{
result[k] = *temp;
temp++;
}
}
#endif