MCPcopy Create free account
hub / github.com/Ayush7614/Daily-Coding-DS-ALGO-Practice / merge

Function merge

Data Structures/gap_method.cpp:15–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13 return gap / 2 + gap % 2;
14}
15void merge(long long arr1[], long long arr2[], int n, int m)
16{
17 int i, j, gap = m + n;
18
19 //we traverse the array till our gap became 0..
20 for (gap = newGap(gap); gap > 0; gap = newGap(gap))
21 {
22
23 //now check the condition when both compared elements are in first array...
24 for (i = 0; i + gap < n; i++)
25 {
26 if (arr1[i] > arr1[i + gap])
27 {
28 swap(arr1[i], arr1[i + gap]);
29 }
30 }
31
32 //when compared elements are in first and second both array...
33 for (j = 0; j < m && i < n; i++, j++)
34 {
35 if (arr1[i] > arr2[j])
36 swap(arr1[i], arr2[j]);
37 }
38
39 //when compared element are in second array...
40 for (j = 0; j + gap < m; j++)
41 {
42 if (arr2[j] > arr2[j + gap])
43 swap(arr2[j], arr2[j + gap]);
44 }
45 }
46}
47
48int main()
49{

Callers 1

mainFunction · 0.70

Calls 2

newGapFunction · 0.85
swapFunction · 0.70

Tested by

no test coverage detected