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

Method push

java/Chapter 3/Question3_1/QuestionB.java:87–102  ·  view source on GitHub ↗
(int stackNum, int value)

Source from the content-addressed store, hash-verified

85 }
86
87 static void push(int stackNum, int value) throws Exception {
88 StackData stack = stacks[stackNum];
89 /* Check that we have space */
90 if (stack.size >= stack.capacity) {
91 if (numberOfElements() >= total_size) { // Totally full
92 throw new Exception("Out of space.");
93 } else { // just need to shift things around
94 expand(stackNum);
95 }
96 }
97 /* Find the index of the top element in the array + 1,
98 * and increment the stack pointer */
99 stack.size++;
100 stack.pointer = nextElement(stack.pointer);
101 buffer[stack.pointer] = value;
102 }
103
104 static int pop(int stackNum) throws Exception {
105 StackData stack = stacks[stackNum];

Callers 1

mainMethod · 0.95

Calls 3

numberOfElementsMethod · 0.95
expandMethod · 0.95
nextElementMethod · 0.95

Tested by

no test coverage detected