import java.util.*; // Stores a set of integers within the given range public class RangeSet { // restriction: cannot use a set private int[] data; private int size; // creates a RangeSet able to store integers from // 0(inclusive) to given max (exclusive) public RangeSet() { data = new boolean[max]; size = 0; } // pre: num is < max of range for this set, throws IllegalArgumentException if otherwise // adds the given number to the set public void add(int num) { if (!data[num]) { data[num] = true; size++; } } // pre: num is < max of range for this set, throws IllegalArgumentException if otherwise // post: removes the given number from the set public void remove(int num) { checkRange(num); if (data[num]) { data[num] = false; size--; } } // pre: num is < max of range for this set, throws IllegalArgumentException if otherwise // post: returns true if the given num is in the set, false otherwise public boolean contains(int num) { checkRange(num); return data[num]; } // post: returns the number of elements in the set public int size() { return size; } // throws an IllegalArgumentException if num is >= max of range private void checkRange(int num) { if (num >= max) { throw new IllegalArgumentException("num to add is outside of range"); } } }