Im a bit stumped here. Im working on building a binary heap class, modeled by an array. I’m trying to take two arrays of strings, and concatenate them together (for a merge function) to create a new array, which I’ll then perform sorting operations on.
Both of the arrays are initialized like so in my interface:
string *heapArray;
Both arrays are constructed as so in my implementation:
heapArray = new string[10];
And the code that I tried, which won’t compile, is this:
merged->heapArray = one->heapArray + two->heapArray;
So obviously I’ve done something wrong here, but I haven’t done any concatenation of raw C++ arrays in the past, mostly play it safe with vectors. Alas, working on this optimization assignment requires it. Any guidance would be appreciated.
I realize I haven’t posted much code, but I get frustrated by people who post mass blocks of code on here. I’ve posted what I think is relevant, but if there is something specific I’m missing which would be helpful, let me know and I’ll add it.
When dealing with straight C++ arrays, the only way to add two of them together like that is to allocate a new array, and insert them one by one from the two source arrays into the new one
EDIT:
Or a memcpy, but that isn’t as easy with a non-basic data type