Package algs13
Class ResizingArrayBag<Item>
java.lang.Object
algs13.ResizingArrayBag<Item>
- All Implemented Interfaces:
- Iterable<Item>
The 
ResizingArrayBag class represents a bag (or multiset) of
  generic items. It supports insertion and iterating over the
  items in arbitrary order.
  
  This implementation uses a resizing array.
  See 
 for a version that uses a singly linked list.
  The add operation takes constant amortized time; the
  isEmpty, and size operations
  take constant time. Iteration takes time proportional to the number of items.
  invalid reference
LinkedBag
For additional documentation, see Section 1.3 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
- Author:
- Robert Sedgewick, Kevin Wayne
- 
Nested Class SummaryNested Classes
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidAdds the item to this bag.booleanisEmpty()Is this bag empty?iterator()Returns an iterator that iterates over the items in the bag in arbitrary order.static voidUnit tests theResizingArrayBagdata type.private voidresize(int capacity) intsize()Returns the number of items in this bag.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.IterableforEach, spliterator
- 
Field Details- 
INIT_CAPACITY- See Also:
 
- 
a
- 
n
 
- 
- 
Constructor Details- 
ResizingArrayBagpublic ResizingArrayBag()Initializes an empty bag.
 
- 
- 
Method Details- 
isEmptyIs this bag empty?- Returns:
- true if this bag is empty; false otherwise
 
- 
sizeReturns the number of items in this bag.- Returns:
- the number of items in this bag
 
- 
resize
- 
addAdds the item to this bag.- Parameters:
- item- the item to add to this bag
 
- 
iteratorReturns an iterator that iterates over the items in the bag in arbitrary order.
- 
mainUnit tests theResizingArrayBagdata type.- Parameters:
- args- the command-line arguments
 
 
-