(int index, int total_size)
| 12 | } |
| 13 | |
| 14 | public boolean isWithinStack(int index, int total_size) { |
| 15 | // Note: if stack wraps, the head (right side) wraps around to the left. |
| 16 | if (start <= index && index < start + capacity) { |
| 17 | // non-wrapping, or "head" (right side) of wrapping case |
| 18 | return true; |
| 19 | } else if (start + capacity > total_size && |
| 20 | index < (start + capacity) % total_size) { |
| 21 | // tail (left side) of wrapping case |
| 22 | return true; |
| 23 | } |
| 24 | return false; |
| 25 | } |
| 26 | } |