Free preview: 2 of 3 free topics used. You can open 1 more without an account.
Sign up free to unlock all 99size = 0 · empty
Capacity 2
Start with room for 2 values and size 0.
Operations (6/20)
1int[] data = new int[2];2int size = 0;34void append(int x) {5if (size == data.length) {6int[] bigger = new int[data.length * 2];7for (int i = 0; i < size; i++) bigger[i] = data[i];8data = bigger;9}10data[size++] = x;11}1213int pop() {14if (size == 0) throw new RuntimeException("empty");15return data[--size];16}
Variables
Work done
Shortcuts: Space play/pause · ← → step · M sound