I'm having a problem with a homework assignment. I had to create a doubly-linked List class with an iterator. I have done this except there is one "display" method that displays a large integer that is stored in this List class. The method is constant and my custom Iterator class will not work with it. Can someone tell me a short-cut to fix this problem?
Here is the display method:
//--- Definition of display()
void BigInt::display(ostream & out) const
{
int blockCount = 0;
const int BLOCKS_PER_LINE = 20; // number of blocks to display per line
for (Iter<short int> it(myList.begin()); ; )
{
out << setfill('0');
if (blockCount == 0)
out << setfill(' ');
if (it == myList.end())
return;
out << setw(3) << *it;
blockCount++ ;
it++;
if (it != myList.end())
{
out << ',';
if (blockCount > 0 && blockCount % BLOCKS_PER_LINE == 0)
out << endl;
}
}
}
That display method is called by this operation method:
inline ostream & operator<<(ostream & out, const BigInt & number)
{
number.display(out);
return out;
}
Is there any way to go through this list without creating a whole new constant Iterator class?