Three stacks in a single array
Stack sizing

The 3 stacks have different size limits:


The 1st stack can have maximum size / 2 elements
The 2nd and 3rd stacks share their storage, they can have size / 2 elements


When there is a peculiar limitation like this, it's good to document it, and hopefully with an explanation of the reasoning.

An alternative approach could have been giving each stack size / 3 space.

Another alternative would be using an array of StackNode objects, where StackNode would store the payload, and a link to the StackNode above it. This way all stacks would have dynamic size, until their total use reaches the capacity of the StackNode array. However, in addition to the extra storage needed (for the links), the logic would be also more complicated to account for the freed spots in the array.

Make final what you can

This field can be final:


private int[] stack;



One statement per line

It's best when you can read code from top to bottom.
When there are multiple statements per line,
it's easy to overlook the right end.
So instead of putting multiple assignments on the same line like this:


first = -1; last = size; mid = (first + last) &gt;&gt; 1;



It would be better to break it up, to have one statement per line.

Clever code

This code is a bit clever:


mid = (first + last) &gt;&gt; 1;



It's best to keep things simple and natural:

mid = (first + last) / 2;


Sure, bit shifting is faster than division.
But it's reasonable to expect the compiler to automatically convert / 2 to use bit shifting instead of division, so that you can write simple, natural, unsurprising code. (I don't know if the compiler actually does that, but in any case, such micro-optimization is likely to be pointless pedantry anyway.)