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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add the key to this set.Return the smallest key in this set>= k
.boolean
Does this set contain the given key?void
Delete the given key from this set.boolean
Does this SET equal that set.Return the largest key in this set<= k
.int
hashCode()
intersects
(SET<K> that) Return the intersection of this set with that set.boolean
isEmpty()
Is this set empty?iterator()
Return an Iterator for this set.static void
max()
Return the key in this set with the maximum value.min()
Return the key in this set with the minimum value.int
size()
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:
iterator
in 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
-