Write a class ResizingStack of ints on an array of initial capacity 2: push doubles the array when it is full; pop halves it when, after the pop, the stack is not empty and exactly one-quarter full. Count the elements copied by all resizes. pop and peek throw NoSuchElementException("stack is empty").
ResizingStackApp reads commands: push N pushes 1 … N, pop N pops N times and prints the last popped value, peek. After each command print the size and capacity, and at the end the number of operations and of copied elements.
For the input
push 5 peek pop 4 pop 1 pop 1
the program prints
push -> size 5, capacity 8
top: 5
peek -> size 5, capacity 8
last popped: 2
pop -> size 1, capacity 2
last popped: 1
pop -> size 0, capacity 2
error: stack is empty
pop -> size 0, capacity 2
Operations: 10, elements copied by resizing: 9