CS 153 Data Structures I

Assignment #7

Due: 3/1/01

Purpose: create a completely generalize container class.

Capabilities:

  1. The container class will have the exact same functionality as Assignment #5
  2. The container will 'hold' objects that have been derived from class CNode


CNode


class CData: public CNode


 In Program 5 you hard coded the Nodes to contain an int.  For Program #7 this int m_data MUST be removed from the Node specification.  Your Node will look something like the following:

class Node
{
public:
    Node();
    virtual bool operator<( Node & rhs ) = 0;
    virtual bool operator==( Node & rhs ) = 0;
    virtual ~Node() {};
    Node * next;
    Node * prev;
};

A sample Find function showing how to use a virtual function (in this case operator==).

bool CBag::Find( Node *pNode )
{
    Node *pTempNode = m_pHead;
    while( pTempNode )
   {
        if( *pTempNode == *pNode ) 
       {
           return( true );
       }
       pTempNode = pTempNode->next; 
   }
   return( false );          
}