home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
SAMPLES
/
ICLCC
/
LETTERDQ.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-07
|
4KB
|
103 lines
/******************************************************************************/
/* */
/* COPYRIGHT: */
/* ---------- */
/* Copyright (C) International Business Machines Corp., 1991,1992. */
/* */
/* DISCLAIMER OF WARRANTIES: */
/* ------------------------- */
/* The following [enclosed] code is sample code created by IBM */
/* Corporation. This sample code is not part of any standard IBM product */
/* and is provided to you solely for the purpose of assisting you in the */
/* development of your applications. The code is provided "AS IS", */
/* without warranty of any kind. IBM shall not be liable for any damages */
/* arising out of your use of the sample code, even if they have been */
/* advised of the possibility of such damages. */
/* */
/******************************************************************************/
/*-------------------------------------------------------------*\
| |
| letterdq.C - 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:
Boolean 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;
Boolean ReadFront = True;
int i;
// Put all characters in the deque.
// Then read it, changing the end to read from
// with every character read.
cout << "\nAdding characters to the back end of the deque:\n";
for (i = 0; String[i] != 0; i ++) {
D.addAsLast(String[i]);
cout << String[i];
}
cout << "\n\nCurrent number of elements in the deque: "
<< D.numberOfElements() << "\n";
cout << "\nContents of the deque:\n";
Print Aprinter;
D.allElementsDo(Aprinter);
cout << "\n\nReading from the deque one element from front, one "
"from back, and so on:\n";
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
}
return(0);
}