home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (c) IBM Corp. 1992 */
- /*--------------------------------------------------------------------------*\
- * *
- | Example program of Building Block SEQUENCE. |
- * *
- \*--------------------------------------------------------------------------*/
-
- #include <iostream.h>
- #include <string.h>
- #include <iseq.h>
-
- typedef ISequence <char> CharSeq;
-
- typedef IIterator <char> CharIterator;
-
- class PrintClass : public CharIterator
- {
- public:
- Boolean applyTo(char &c)
- {
- cout << c; // Print the character
- return(True);
- }
- };
-
-
- char * String = "BuildingBlocks";
-
- /*--------------------------------------------------------------------------*\
- * Main program *
- \*--------------------------------------------------------------------------*/
- int main() {
- CharSeq CS;
- CharSeq::Cursor cursor(CS);
-
- PrintClass Print;
- int i;
-
- cout << "\n*** Example of SEQUENCE use ***\n";
-
- for (i = 0; String[i] != 0; i++) // Put all characters in the
- { // sequence.
- CS.add(String[i]);
- }
-
- cout << "\nSequence contains:\n"; // Print the contents
- CS.allElementsDo(Print);
- cout << "\nNumber of elements = " << CS.numberOfElements() << "\n";
-
- while (CS.numberOfElements () >= 5) {
- CS.setToPosition(5, cursor);
- CS.allElementsDo(Print);
- cout << "\n";
- CS.removeAt(cursor);
- }
-
- cout << "\nSequence without the tail:\n"; // Print the contents again
- CS.allElementsDo(Print);
- cout << "\nNumber of elements = \n" << CS.numberOfElements();
-
- cout << "\n*** End of example ***\n";
-
- return(0);
- }
-