class Bag

Bag. More...

Definition#include <bag.h>
Template formBag<templateclass T>
Inherited bySet
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Methods

Protected Methods


Detailed Description

This class implements the Bag datatype template.

 Bag ()

Constructor.

Bag ()

Destructor.

bool  addHead (T element)

Add element to head of bag.

Parameters:
elementElement to be added.

Returns: true, if element has been added; false, if not.

bool  addTail (T element)

Add element to tail of bag.

Parameters:
elementElement to be added.

Returns: true, if element has been added; false, if not.

void  remove (T element)

Remove element from bag.

Parameters:
elementElement to be removed.

inline void  removeHead ()

Remove first element from bag.

inline void  removeTail ()

Remove last element from bag.

inline bool  contains (const T& element)

[const]

Check, if bag contains an element.

Parameters:
elementElement to be checked to be in the bag.

inline cardinal  getCount ()

[const]

Get number of elements in the bag.

Returns: Number of elements.

inline bool  first (T& element)

Get first element. If true is returned, the given reference will be a reference to the element.

Parameters:
elementReference to hold the element's reference.

Returns: true, if the reference is valid.

inline bool  last (T& element)

Get last element. If true is returned, the given reference will be a reference to the element.

Parameters:
elementReference to hold the element's reference.

Returns: true, if the reference is valid.

inline bool  next (T& element)

Get next element. If true is returned, the given reference will be a reference to the element.

Parameters:
elementReference to hold the element's reference.

Returns: true, if the reference is valid.

inline bool  prev (T& element)

Get previous element. If true is returned, the given reference will be a reference to the element.

Parameters:
elementReference to hold the element's reference.

Returns: true, if the reference is valid.

BagNode<T>*  findNode (const T& element)

[protected const]

Get BagNode for an element.

Parameters:
elementElement.

Returns: Pointer to BagNode or NULL, if element is not in the bag.

void  removeNode (BagNode<T>* node)

[protected]

Remove a BagNode.

Parameters:
nodeBagNode to be removed.