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 >
Wrap
C/C++ Source or Header
|
1997-07-23
|
1KB
|
59 lines
// ---------------------------------------------------------------------------
// Copyright (C) 1994 Borland International
// ideqlist.cpp
// Must link with myclass.cpp.
// ---------------------------------------------------------------------------
#include <classlib/deques.h>
#include <iostream.h>
#include <strstrea.h>
#include "../myclass.h"
typedef TIDequeAsDoubleList<MyClass> ContainerType;
typedef TIDequeAsDoubleListIterator<MyClass> IteratorType;
const int MaxItems=6;
void ForEachCallBack(MyClass& mc, void* s)
{
cout << (char*)s << mc << endl;
}
void AddItems(ContainerType& container, int numItems)
{
for( int i=numItems; i>0; i-- )
{
char buf[80];
ostrstream str( buf, sizeof(buf) );
str << i << " hello" << ends;
if( i % 2 == 0 )
container.PutLeft( new MyClass(buf) );
else
container.PutRight( new MyClass(buf) );
}
}
void UseForwardIterator(ContainerType& container)
{
IteratorType iterator(container);
while( iterator )
{
cout << *iterator.Current() << endl;
iterator++;
}
}
int main()
{
ContainerType container;
AddItems(container, MaxItems);
cout << "--- Starting ForEach" << endl;
container.ForEach(ForEachCallBack, (void*)"FE ");
cout << "--- Starting Iterator" << endl;
UseForwardIterator(container);
return 0;
}