CS 153 Data Structures I
Programming Assignment #5

Due: 2/15/01

This programming assignment is designed to:

In order to meet these goals you may: Changing from a Forward list to a Forward/Backward list just adds functionality.  Instead of always needing to start at the Head of the list, you will now be able to work from either end.  The new functions below are just exensions of what you have already done.

The 2nd significant change from project4 is more philosophical.  Previously, when you wanted to Display the content of the CBag container you called a CBag::Display(...) member function.  For reasons that will be discussed in class this is normally considered an undesirable design.  What is preferred is called an iterator capability. An iterator capability is made up of 3 CBag member functions and 1 CBag member variable.  Under this new arrangement, when you need to display the content of the container you will:
mybag.Reset()
while( ! mybag.EOC() )
{
 some-int = mybag.GetNext();
 do-whatever-with-the-int;       //put the integer into a CListBox or . . .
}

Here is a suggested prototype for iterator capability


To upgrade to a doubly linked list, you will need to modify your struct Node so that it has a prev pointer.  Your next pointer will work in the same manner as it did in project4, while the newly added prev pointer will point to the Node which precedes it.  You should modify your existing functions to support this new pointer.  Since struct Node has only 1 function, this only involves

You will need to add 2 new pointers to the CBag class.
a Node * m_tail (comparible to m_head) which always points to the last Node in the list
a Node * m_current described above.  This pointer will be modified by Reset() and GetNext() and will keep track of the current position in the list.

You must remove the CBag::Display() function (the contents of the bag can be retreived by successive calls to GetNext() ) and replace it will a ...Dlg::Display(CBag whichBag) function.  Call this function from each of the OnButtonxxx functions that needs to display the container contents.  Since this ...Dlg::Display(...) function doesn't need to be called from a click of a button, the easiest way to add it is to right click on the ...Dlg class and select AddNewMemberFunction.  The wizard will add the function prototype to the ...Dlg class and will build the
...Dlg::Display()
{           structure in the ...Dlg.cpp
             where you add the mybag.Reset()
                           and
             the while ( ! mybag.EOC() ) loop
}

You will need add the following functions in your CBag class; these are in addition to the functions you already have.