Class Bag<Item>

Object
  extended by Bag<Item>
All Implemented Interfaces:
Iterable<Item>

public class Bag<Item>
extends Object
implements Iterable<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

Bag

public Bag()
Create an empty stack.

Method Detail

isEmpty

public boolean isEmpty()
Is the BAG empty?


size

public int size()
Return the number of items in the bag.


add

public void add(Item item)
Add the item to the bag.


iterator

public java.util.Iterator<Item> iterator()
Return an iterator that iterates over the items in the bag.

Specified by:
iterator in interface Iterable<Item>