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

Method pop

java/Chapter 3/Question3_1/QuestionB.java:104–114  ·  view source on GitHub ↗
(int stackNum)

Source from the content-addressed store, hash-verified

102 }
103
104 static int pop(int stackNum) throws Exception {
105 StackData stack = stacks[stackNum];
106 if (stack.size == 0) {
107 throw new Exception("Trying to pop an empty stack.");
108 }
109 int value = buffer[stack.pointer];
110 buffer[stack.pointer] = 0;
111 stack.pointer = previousElement(stack.pointer);
112 stack.size--;
113 return value;
114 }
115
116 static int peek(int stackNum) {
117 StackData stack = stacks[stackNum];

Callers 1

mainMethod · 0.95

Calls 1

previousElementMethod · 0.95

Tested by

no test coverage detected