Package algs35
Class SET<K extends Comparable<? super K>>
java.lang.Object
algs35.SET<K>
- All Implemented Interfaces:
Iterable<K>
The
SET class represents an ordered set. It assumes that
the elements are Comparable.
It supports the usual add, contains, and delete
methods. It also provides ordered methods for finding the minimum,
maximum, floor, and ceiling.
This implementation uses a balanced binary search tree. The add, contains, delete, minimum, maximum, ceiling, and floor methods take logarithmic time.
For additional documentation, see Section 4.5 of Algorithms in Java, 4th Edition by Robert Sedgewick and Kevin Wayne.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd the key to this set.Return the smallest key in this set>= k.booleanDoes this set contain the given key?voidDelete the given key from this set.booleanDoes this SET equal that set.Return the largest key in this set<= k.inthashCode()intersects(SET<K> that) Return the intersection of this set with that set.booleanisEmpty()Is this set empty?iterator()Return an Iterator for this set.static voidmax()Return the key in this set with the maximum value.min()Return the key in this set with the minimum value.intsize()Return the number of keys in this set.toString()String represenation of this set.Return the union of this set with that set.Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
SET
public SET()Create an empty set.
-
-
Method Details
-
isEmpty
Is this set empty? -
add
Add the key to this set. -
contains
Does this set contain the given key? -
delete
Delete the given key from this set. -
size
Return the number of keys in this set. -
iterator
Return an Iterator for this set.- Specified by:
iteratorin interfaceIterable<K extends Comparable<? super K>>
-
max
Return the key in this set with the maximum value. -
min
Return the key in this set with the minimum value. -
ceil
Return the smallest key in this set>= k. -
floor
Return the largest key in this set<= k. -
union
Return the union of this set with that set. -
intersects
Return the intersection of this set with that set. -
equals
Does this SET equal that set. -
hashCode
-
toString
String represenation of this set. -
main
-