You simply want a k-way merge. Here is some sample code for how to implement that (untested):
Code:
//Inputs a .. e
const object a[42]; // can be any length
//...
const object e[1337]; // can be any length
//Output
object *out[42+...+1337];
struct Inputs {
object *ptr;
int count;
bool operator < (const Inputs & b) { return *ptr < *(b.ptr); }
};
//Setup
Inputs in[5];
int alive = 5, idx = 0;
in[0].ptr = a; in[0].count = 42;
//...
in[4].ptr = e; in[4].count = 1337;
while (alive > 0)
{
//TODO: Insert basic algorithm here, to sort 'alive' items in array 'in'
//by what their 'ptr' points to e.g. std::sort(in[0], in[5]);
out[idx++] = in[0].ptr++;
if (--in[0].count == 0)
in[0] = in[--alive];
}
//Done: output is in the 'out' array.