public class BitBucket { private int[] counts; public BitBucket() { counts = new int[10]; } private void grow(int size) { int[] newElems = new int[size]; System.arraycopy(counts, 0, newElems, 0, counts.length); counts = newElems; } public void enqueue(int v) { if (v >= counts.length) grow(2*v+1); counts[v]++; } public int removeFirst() { for (int i=0; i < counts.length; i++) { if (counts[i] > 0) { counts[i]--; return i; } } throw new java.util.NoSuchElementException(); } public boolean contains(int v) { return counts[v] > 0; } public boolean isEmpty() { for (int i=0; i < counts.length; i++) { if (counts[i] > 0) return false; } return true; } }