Package dsa
Class Set<T extends Comparable<T>>
java.lang.Object
dsa.Set<T>
- Type Parameters:
T
- the type of items in the set.
- All Implemented Interfaces:
Iterable<T>
An iterable data type to represent an ordered set of items.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Addsitem
to this set, if it is not already present.boolean
Returnstrue
if this set containsitem
, andfalse
otherwise.void
Deletesitem
from this set.boolean
isEmpty()
Returnstrue
if this set is empty, andfalse
otherwise.iterator()
Returns an iterator to iterate over the items in this set in sorted order.static void
Unit tests the data type.int
size()
Returns the number of items in this set.toString()
Returns a string representation of this set.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Set
public Set()Constructs an empty set.
-
-
Method Details
-
isEmpty
public boolean isEmpty()Returnstrue
if this set is empty, andfalse
otherwise.- Returns:
true
if this set is empty, andfalse
otherwise.
-
size
public int size()Returns the number of items in this set.- Returns:
- the number of items in this set.
-
add
Addsitem
to this set, if it is not already present.- Parameters:
item
- the item.
-
contains
Returnstrue
if this set containsitem
, andfalse
otherwise.- Parameters:
item
- the item.- Returns:
true
if this set containsitem
, andfalse
otherwise.
-
delete
Deletesitem
from this set.- Parameters:
item
- the item.
-
iterator
Returns an iterator to iterate over the items in this set in sorted order.- Specified by:
iterator
in interfaceIterable<T extends Comparable<T>>
- Returns:
- an iterator to iterate over the items in this set in sorted order.
-
toString
Returns a string representation of this set. -
main
Unit tests the data type.- Parameters:
args
- the command-line arguments.
-