Package dsa
Class LinkedBag<T>
java.lang.Object
dsa.LinkedBag<T>
- Type Parameters:
T
- the type of items in the bag.
This data type provides an implementation of the Bag API, using a linked-list as the underlying data structure.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Addsitem
to this bag.boolean
isEmpty()
Returnstrue
if this bag is empty, andfalse
otherwise.iterator()
Returns an iterator to iterate over the items in this bag.static void
Unit tests the data type.int
size()
Returns the number of items in this bag.toString()
Returns a string representation of this bag.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
-
LinkedBag
public LinkedBag()Constructs an empty bag.
-
-
Method Details
-
isEmpty
public boolean isEmpty()Returnstrue
if this bag is empty, andfalse
otherwise. -
size
public int size()Returns the number of items in this bag. -
add
Addsitem
to this bag. -
toString
Returns a string representation of this bag. -
iterator
Returns an iterator to iterate over the items in this bag. -
main
Unit tests the data type.- Parameters:
args
- the command-line arguments.
-