The Set ADT

Solution

A set is a collection of distinct elements, with no order. add puts an item into the set if it is not already there. remove takes an item out of the set if it is there. contains reports whether an item is in the set. size reports how many items the set holds.

Solution

For contains, it reports whether the item is in the set. For add and remove, it reports whether the call changed the set. add returns true when it added the item and false when the item was already present. remove returns true when it removed the item and false when the item was not present.

Solution
set.add(14);       true
set.add(27);       true
set.add(14);       false
set.contains(27);  true
set.remove(35);    false
set.remove(14);    true
set.contains(14);  false
set.size();        1
Solution

A set has no order, so it has no positions. There is no first item, no last item, and no item at index i to ask for.