You're welcome!

But note that implementing this algorithm is probably not the solution to your problem.

As you said this was homework, I assume you're asked for more than that.

This solution is theory only. It would not be acceptable for a professional project.

As a teacher, I would only rate this answer from 20% to 50% depending on the expected level.

What

you should do is probably not implement a fully working solution, but ask the right questions about your simple solution, and provide the right answers.

If you intend to do this by yourself, you might want to stop reading here.

Otherwise, I'll give you some hints below in the form of questions you should be asking to yourself. Stop reading when you think you have enough to continue on your own. The answers to these questions are of course in my book, but if you need them, I can post them here.

You should think about the merge method as a function taking a pair of threes as its argument and returning a tree.

Is your solution a true function?

If you think it is, can you explicitly describe the domain and codomain of this function?

How long will it take for your implementation to compute the result?

Might it throw an exception?

Will it always terminate (either by returning a resulting tree or throwing an exception)?

What about the cardinality of the result compared to the cardinality or the arguments?

What may happen if you swap the two elements of the argument pair?

If by answering the above questions it appears that the solution is not optimal, what should you do to make it work?