Project 2
Public Member Functions | List of all members
Bag< ItemType > Class Template Reference

Public Member Functions

 Bag ()
 
 ~Bag ()
 
int size () const
 
bool isEmpty () const
 
bool add (const ItemType &newEntry)
 
void clear ()
 
bool contains (const ItemType &anEntry) const
 
int getFrequencyOf (const ItemType &anEntry) const
 
std::vector< ItemType > toVector () const
 

Constructor & Destructor Documentation

◆ Bag()

template<class ItemType >
Bag< ItemType >::Bag ( )

Constructor

◆ ~Bag()

template<class ItemType >
Bag< ItemType >::~Bag ( )

Destructor

Member Function Documentation

◆ add()

template<class ItemType>
bool Bag< ItemType >::add ( const ItemType &  newEntry)

Adds a new item to the bag.

Postcondition
If successful, newEntry is added to the bag, and the number of items in the bag has increased by 1.
Parameters
newItemThe item (of datatype ItemType) to be added.
Returns
True if insert was successful, or false if not.

◆ clear()

template<class ItemType >
void Bag< ItemType >::clear ( )

Deletes all entries from this bag.

Postcondition
The bag contains no items, and the number of items is 0.

◆ contains()

template<class ItemType>
bool Bag< ItemType >::contains ( const ItemType &  anEntry) const

Tests whether this bag contains a given item.

Parameters
anItemThe item to locate.
Returns
True if bag contains anEntry, or false otherwise.

◆ getFrequencyOf()

template<class ItemType>
int Bag< ItemType >::getFrequencyOf ( const ItemType &  anEntry) const

Returns the number of times a given item appears in this bag.

Parameters
anItemThe item to locate.
Returns
The integer number of times the item is in this bag.

◆ isEmpty()

template<class ItemType >
bool Bag< ItemType >::isEmpty ( ) const

Determines whether this bag is empty.

Returns
True if the bag has no items, or false if not.

◆ size()

template<class ItemType >
int Bag< ItemType >::size ( ) const

Returns the number of items in the bag.

Returns
The integer number of items in bag.

◆ toVector()

template<class ItemType >
std::vector< ItemType > Bag< ItemType >::toVector ( ) const

Empties and then fills a given vector with all items that are in this bag.

Returns
A vector containing all the items in the bag.

The documentation for this class was generated from the following files: