MERGE ARRAYS

I have a working merge sort but I would like the final output to merge both W & H arrays in the code below. Please anyone with help. thanks.


// MERGE SORT FOR CYBERNECTICS LTD.
#include <iostream>
#include <conio.h>
#include <chrono>

using namespace std;
using namespace std::chrono;


void merge(int *, int, int, int);
void sort_merge(int *w, int lower, int higher)
{

int avg;
if (lower < higher)
{
avg = (lower + higher) / 2;
sort_merge(w, lower, avg);
sort_merge(w, avg + 1, higher);
merge(w, lower, higher, avg);
}
return;
}
void merge(int *w, int lower, int higher, int avg)
{
int i, z, v, c[50];
i = lower;
v = lower;
z = avg + 1;
while (i <= avg && z <= higher)
{
if (w[i] < w[z])
{
c[v] = w[i];
v++;
i++;
}
else
{
c[v] = w[z];
v++;
z++;
}
}
while (i <= avg)
{
c[v] = w[i];
v++;
i++;
}
while (z <= higher)
{
c[v] = w[z];
v++;
z++;
}
for (i = lower; i < v; i++)
{
w[i] = c[i];
}
}


void timefunction()
{
long long number = 0;

for (long long i = 0; i != 20000000; ++i)
{
number += 5;
}
}

int main()
{
cout << "THE MERGE SORT FOR CYBERNETICS LTD.\n" << endl << endl;
int w[20], i, h[20];
cout << "ENTER DATA ARRAY ELEMENTS:\n";
for (i = 0; i < 15; i++)
{
cout << "\n";
cin >> w[i];
}
cout << "\n\n";

sort_merge(w, 0, 14);
cout << "MERGE-SORTED ARRAY:\n";
for (i = 0; i < 15; i++)
{
cout << w[i] << " ";
}

cout << "\n\n";

cout << "ENTER DATA ARRAY ELEMENTS:\n";
for (i = 0; i < 15; i++)
{
cout << "\n";
cin >> h[i];
}
cout << "\n\n";

sort_merge(h, 0, 14);
cout << "MERGE-SORTED ARRAY:\n";
for (i = 0; i < 15; i++)
{
cout << h[i] << " ";
}



high_resolution_clock::time_point tp1 = high_resolution_clock::now();
timefunction();
high_resolution_clock::time_point tp2 = high_resolution_clock::now();

auto duration = std::chrono::duration_cast<std::chrono::microseconds>(tp2 - tp1).count();

cout << "\n\n";
cout << "TIME CONSUMED FOR MERGE SORT IN MICROSECONDS" << ": ";
cout << duration;


_getch();
}
First, in would improve code readability if you would edit your post to add code tags and systematic indentation. see http://www.cplusplus.com/articles/jEywvCM9/

I would like the final output to merge both W & H arrays

Do you mean:
1
2
3
4
5
int W[20];
int H[20];
int F[40];
// copy W and H to F and merge-sort
// show F 
Please how do I copy W and H to F and merge sort and show F. I am new to this C++.

Please how do I ... show F.

How do you show W and H in your code now?

Please how do I ... merge sort [array]

How do you merge sort W and H in your code now?

Please how do I copy

With a loop?


You are new. Have you looked at http://www.cplusplus.com/doc/tutorial/ and other similar sources?
You were asked in your previous thread to use code tags when posting code. If you're not going to make the slightest bit of effort to make your posts readable, why should we spend the slightest bit of effort helping you?
Topic archived. No new replies allowed.