home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
VSCPPv8.zip
/
VACPP
/
IBMCPP
/
samples
/
IOC
/
LETTERDQ
/
LETTERDQ.CPP
< prev
next >
Wrap
Text File
|
1995-03-15
|
3KB
|
100 lines
/*************************************************************************
IBM C/C++ Tools Version 3.00 - Collection Class Library
(C) Copyright IBM Corporation 1992 ,1995, Licensed Program-Property of
IBM. All Rights Reserved. US Government Users Restricted Rights - Use,
duplication or disclosure restricted by GSA ADP Schedule Contract with
IBM Corp.
*************************************************************************/
/*-------------------------------------------------------------*\
| |
| letterdq.CPP - Letter Double Ended Queue |
| This is an example of using a Deque. |
| """"" |
\*-------------------------------------------------------------*/
#include <iostream.h>
#include <ideqseq.h>
#include <ideque.h>
// Let's use the default deque
typedef IDeque <char> Deque;
// The deque requires iteration to be const
typedef IConstantIterator <char> CharIterator;
class Print : public CharIterator
{
public:
IBoolean applyTo(char const&c)
{
cout << c;
return True;
}
};
/*-------------------------------------------------------------*\
| Test variables |
\*-------------------------------------------------------------*/
char *String = "Teqikbonfxjme vralz o.gdya eospu o wr cu h";
/*-------------------------------------------------------------*\
| Main program |
\*-------------------------------------------------------------*/
int main()
{
Deque D;
char C;
IBoolean ReadFront = True;
int i;
// Put all characters in the deque.
// Then read it, changing the end to read from
// with every character read.
cout << endl
<< "Adding characters to the back end of the deque:" << endl;
for (i = 0; String[i] != 0; i ++) {
D.addAsLast(String[i]);
cout << String[i];
}
cout << endl << endl
<< "Current number of elements in the deque: "
<< D.numberOfElements() << endl;
cout << endl
<< "Contents of the deque:" << endl;
Print Aprinter;
D.allElementsDo(Aprinter);
cout << endl << endl
<< "Reading from the deque one element from front, one "
<< "from back, and so on:" << endl;
while (!D.isEmpty())
{
if (ReadFront) // Read from front of Deque
{
C = D.firstElement(); // Get the character
D.removeFirst(); // Delete it from the Deque
}
else
{
C = D.lastElement();
D.removeLast();
}
cout << C;
ReadFront = !ReadFront; // Switch to other end of Deque
}
cout << endl;
return(0);
}