home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / deques.pak / IDEQLIST.CPP < prev    next >
C/C++ Source or Header  |  1997-07-23  |  1KB  |  59 lines

  1. // ---------------------------------------------------------------------------
  2. // Copyright (C) 1994 Borland International
  3. // ideqlist.cpp
  4. //    Must link with myclass.cpp.
  5. // ---------------------------------------------------------------------------
  6.  
  7. #include <classlib/deques.h>
  8. #include <iostream.h>
  9. #include <strstrea.h>
  10. #include "../myclass.h" 
  11.  
  12. typedef TIDequeAsDoubleList<MyClass> ContainerType;
  13. typedef TIDequeAsDoubleListIterator<MyClass> IteratorType;
  14.  
  15. const int MaxItems=6;
  16.  
  17. void ForEachCallBack(MyClass& mc, void* s)
  18. {
  19.     cout << (char*)s << mc << endl;
  20. }
  21.  
  22. void AddItems(ContainerType& container, int numItems)
  23. {
  24.     for( int i=numItems; i>0; i-- )
  25.         {
  26.         char buf[80];
  27.         ostrstream str( buf, sizeof(buf) );
  28.         str << i << " hello" << ends;
  29.         if( i % 2 == 0 )
  30.             container.PutLeft( new MyClass(buf) );
  31.         else
  32.             container.PutRight( new MyClass(buf) );
  33.         }
  34. }
  35.  
  36. void UseForwardIterator(ContainerType& container)
  37. {
  38.     IteratorType iterator(container);
  39.     while( iterator )
  40.         {
  41.         cout << *iterator.Current() << endl;
  42.         iterator++;
  43.         }
  44. }
  45.  
  46. int main()
  47. {
  48.     ContainerType container;
  49.     AddItems(container, MaxItems);
  50.   
  51.     cout << "--- Starting ForEach" << endl;
  52.     container.ForEach(ForEachCallBack, (void*)"FE ");
  53.   
  54.     cout << "--- Starting Iterator" << endl;
  55.     UseForwardIterator(container);
  56.   
  57.     return 0;
  58. }
  59.