Q3_01_Three_in_One - MultiStack.java
Hello,
I'm trying to understand code from MultiStack.java file.
Everything seems to be good, except one thing.
Please, take a look at line 24. In what cases if clause could be true?
According to your code, method isWithinStackCapacity called only at line 116 with param index, which came from lastCapacityIndex function call. But lastCapacityIndex function did not return negatives values or values that more or equal than values.length.
So maybe if clause at line 24 is redundant?
Thank you!
Yeah, I think you're right; the author does a lot of "defensive" checks in these solutions.
In my opinion these should have been assertions instead. That is, rather than if(bad) return;, simply do assert !bad;. Oh well, it's not my book; I don't get a vote.