There's no bug in your implementation (at least I don't see any, imho) The problem is that the merging you have done is not for two sorted arrays (it's for several bunches of sorted numbers). Case you had feed two already sorted arrays you'd have the result sorted correctly.
The merge sorting algorithm begins with splitting the input into two parts of sorted arrays. This is done by switching arrays when you detect the element is not in order (it is not greater to last number) You get the first ordered set to fill an array (the first a elements of initial list which happen to be in order, to put into array A, and the second bunch of elements to put them into array B. This produces two arrays that can be merged (because they are already in order) and this merging makes the result a larger array (this fact is what warrants the algorithm will make larger and larger arrays at each pass and warrants it will finish at some pass. You don't need to operate array by array, as at each pass the list has less and less packs of larger bunch of sorted elements. in your case:
1st pass input (the switching points are where the input
is not in order, you don't see them, but you switch arrays
when the next input number is less than the last input one):
{5}, {4, 9}, {-1, 3}, {16}, {-11} (See note 2)
after first split:
{5}, {-1, 3}, {-11}
{4, 9}, {16}
after first merge result:
{4, 5, 9}, {-1, 3, 16}, {-11}
after second pass split:
{4, 5, 9}, {-11}
{-1, 3, 16}
result:
{-1, 3, 4, 5, 9, 16}, {-11}
third pass split:
{-1, 3, 4, 5, 9, 16}
{-11}
third pass result:
{-11, -1, 3, 4, 5, 9, 16}
The algorithm finishes when you don't get two bunches of ordered streams (you don't switch arrays), and you cannot divide further the stream of data.
Your implementation only executes one pass of merge sorting algorithm you need to implement it completely to get sorted output. The algorithm was designed to make it possible to do several passes when input is not feasible to put in arrays (as you do, so it doesn't fully illustrate the thing with arrays). Case you have it read from files, you'll see the idea better.
NOTE
Sort programs for huge amounts of data use merging algorithm for bunchs of data that are quicksort'ed first, so we start with buckets of data that don't fit in an array all together.
NOTE 2
The number 16 after number 3 should have been in the same bunch as previous bunch, making it {-1, 3, 16}, but as they where in different arrays at first, and I have not found any way to put them in a list that splits into this arrangement, I have forced the buckets as if 16 < 3, switching artificially the arrays on splitting the input. This could affect the final result in making an extra pass through the data, but doesn't affect the final result, which is a sorted list of numbers. I have made this on purpose, and it is not a mistake (it has no relevance to explain how the algorithm works) Anyway, the algorithm switches lists (I don't like to use arrays when describing this algoritm, as normally merging algorithms don't operate on arrays, as arrays are random access, while lists must be accessed by some iterator means from beginning to end, which is the requirement of the merging sort algorithm) The same happens to {4, 9}, {16} after the first split, just imagine the result of the comparisons was the one shown, as after the first merge everything is correct.
aaorbbare not sorted when it is called. To see this, note that the relative order of the elements within eitheraaorbbis preserved by the merge. For instance, if element x precedes element y inaa, then x is guaranteed to precede y incc. There is no mechanism for interchanging them. So, you need to re-think what you're doing.