More directly, I organize them by wherever I find space.
Sort by height and you might be able to reduce shelf spacing enough to make room to add a shelf to the bookcase.
Even more, if your bookcase has adjustable shelves (for example, via dowels), you can compute the optimal shelf arrangement and book placement, totally customized to your books.
And if you want extra credit, also take into consideration the width of each book, so you know when you reach the shelf size.
I do not admit of having spent hours on this many years ago, nor of still having the code solving it somewhere.
Tbh I was expecting a supercharged Dewey Decimals...