edu.cornell.cs.cs2110
Interface Bag<T>

Type Parameters:
T - the type of elements contained in this Bag.
All Superinterfaces:
Iterable<T>
All Known Implementing Classes:
AbstractBag, AdjustablePriorityQueue, PriorityQueue, Queue, RandomBag, Stack

public interface Bag<T>
extends Iterable<T>

This interface is for multisets, an abstract datatype in which elements can occur multiple times but order is not important. One can put elements in using insert(Object) and take them out using extract(), and these two operations can be done in any order. The order in which the elements are extracted depends on the implementation.


Method Summary
 void clear()
          Removes all elements from the data structure.
 T extract()
          Extracts an element from the data structure.
 void insert(T item)
          Inserts an element into the data structure.
 boolean isEmpty()
          Tests whether the data structure is empty.
 int size()
          Returns the number of elements contained in the data structure.
 
Methods inherited from interface java.lang.Iterable
iterator
 

Method Detail

insert

void insert(T item)
Inserts an element into the data structure.

Parameters:
item - the element to insert

extract

T extract()
          throws NoSuchElementException
Extracts an element from the data structure. The element is deleted.

Returns:
the element extracted
Throws:
NoSuchElementException - if the data structure is empty

isEmpty

boolean isEmpty()
Tests whether the data structure is empty.

Returns:
true if the data structure contains no elements

size

int size()
Returns the number of elements contained in the data structure.

Returns:
the number of elements

clear

void clear()
Removes all elements from the data structure.