MCPcopy Create free account
hub / github.com/careercup/ctci / isWithinStack

Method isWithinStack

java/Chapter 3/Question3_1/StackData.java:14–25  ·  view source on GitHub ↗
(int index, int total_size)

Source from the content-addressed store, hash-verified

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}

Callers 1

shiftMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected