ObjectBag<Item>
public class Bag<Item>
The Bag class represents a bag (or multiset) of generic items. It supports insertion and iterating over the items in arbitrary order.
The add, isEmpty, and size operation take constant time. Iteration takes time proportional to the number of items.
For additional documentation, see Section 1.3 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
| Constructor Summary | |
|---|---|
Bag()
Create an empty stack. |
|
| Method Summary | |
|---|---|
void |
add(Item item)
Add the item to the bag. |
boolean |
isEmpty()
Is the BAG empty? |
java.util.Iterator<Item> |
iterator()
Return an iterator that iterates over the items in the bag. |
int |
size()
Return the number of items in the bag. |
| Methods inherited from class Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Bag()
| Method Detail |
|---|
public boolean isEmpty()
public int size()
public void add(Item item)
public java.util.Iterator<Item> iterator()
iterator in interface Iterable<Item>