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

Method shift

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

Source from the content-addressed store, hash-verified

61 }
62
63 public static void shift(int stackNum) {
64 StackData stack = stacks[stackNum];
65 if (stack.size >= stack.capacity) {
66 int nextStack = (stackNum + 1) % number_of_stacks;
67 shift(nextStack); // make some room
68 stack.capacity++;
69 }
70 for (int i = (stack.start + stack.capacity - 1) % total_size; // end of array
71 stack.isWithinStack(i, total_size);
72 i = previousElement(i)) {
73 buffer[i] = buffer[previousElement(i)];
74 }
75 buffer[stack.start] = 0;
76 stack.start = nextElement(stack.start); // move start start
77 stack.pointer = nextElement(stack.pointer); // move stack pointer
78 stack.capacity--; // return capacity to original
79 }
80
81 /* Expand stack by shifting over other stacks */
82 public static void expand(int stackNum) {

Callers 1

expandMethod · 0.95

Calls 3

isWithinStackMethod · 0.95
previousElementMethod · 0.95
nextElementMethod · 0.95

Tested by

no test coverage detected