home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / SAMPLES / COMPILER / SAMPLE06 / AUTHORS1.CPP next >
Text File  |  1993-04-03  |  7KB  |  175 lines

  1. //+----------------------------------------------------------------------------+
  2. //| PROGRAM NAME: AUTHORS2.CPP                                                 |
  3. //| ------------                                                               |
  4. //|                                                                            |
  5. //| COPYRIGHT:                                                                 |
  6. //| ----------                                                                 |
  7. //|  Copyright (C) International Business Machines Corp., 1992,1993.           |
  8. //|                                                                            |
  9. //| DISCLAIMER OF WARRANTIES:                                                  |
  10. //| -------------------------                                                  |
  11. //|  The following [enclosed] code is sample code created by IBM Corporation.  |
  12. //|  This sample code is not part of any standard IBM product and is provided  |
  13. //|  to you solely for the purpose of assisting you in the development of      |
  14. //|  your applications.  The code is provided "AS IS", without warranty of     |
  15. //|  any kind.  IBM shall not be liable for any damages arising out of your    |
  16. //|  use of the sample code, even if they have been advised of the             |
  17. //|  possibility of such damages.                                              |
  18. //|                                                                            |
  19. //| REVISION LEVEL: 1.0                                                        |
  20. //| ---------------                                                            |
  21. //|                                                                            |
  22. //+----------------------------------------------------------------------------+
  23. //| Purpose     : Demonstrates use of the DataInTree class to store author     |
  24. //|               and book data in the n-ary tree container.                   |
  25. //| Author      : njC Sales                                                    |
  26. //| Date        : 27 October 1992                                              |
  27. //+----------------------------------------------------------------------------+
  28.  
  29. #include <stdio.h>
  30. #include "datntree.hpp"
  31.  
  32. void main()
  33. {
  34.    char *authors[] = {"Asimov, Isaac",
  35.                       "Sales, Kevin Matthew",
  36.                       "Stroustrup, Bjarne",
  37.                       "Richie, Dennis"
  38.                      };
  39.  
  40.    char *AIbooks[] = {"Foundation",
  41.                       "I Robot",
  42.                       "Caves of Steel"
  43.                      };
  44.  
  45.    char *SKbooks[] = {"Compiler Design",
  46.                       "Man Machine Communication",
  47.                       "I came, I C"
  48.                      };
  49.  
  50.    char *SBbooks[] = {"C++ Programming Language",
  51.                       "The ARM",
  52.                      };
  53.  
  54.    char *RDbooks[] = {"C Programming Language",
  55.                       "Yet another C",
  56.                      };
  57.  
  58.    DataInTree          Mommy;
  59.    DataInTree          *childWalker, *childWalker2;
  60.    int index, ndx2;
  61.  
  62.    for (index= 0; index < sizeof(authors)/sizeof(char *); index++)
  63.    {
  64.       Mommy.addChild(new DataInTree(DataInTree(authors[index])));
  65.    }
  66.  
  67.    printf("The Authors are.. tah dahhhhh\n");
  68.  
  69.    for (childWalker= (DataInTree *)Mommy.getChild();
  70.         childWalker != NULL;
  71.         childWalker= (DataInTree *)childWalker->getRight())
  72.    {
  73.       childWalker->display();
  74.    }
  75.  
  76.    printf("Now Adding books to authors\n");
  77.  
  78.    for (index= 0, childWalker= (DataInTree *)Mommy.getChild();
  79.         childWalker != NULL;
  80.         index++,  childWalker= (DataInTree *)childWalker->getRight())
  81.    {
  82.       childWalker->display();
  83.       switch(index)
  84.       {
  85.          case 0:
  86.             for (ndx2= 0; ndx2 < sizeof(AIbooks)/sizeof(char *); ndx2++)
  87.             {
  88.                childWalker->addChild(new DataInTree(DataInTree(AIbooks[ndx2])));
  89.             }
  90.             break;
  91.  
  92.          case 1:
  93.             for (ndx2= 0; ndx2 < sizeof(SKbooks)/sizeof(char *); ndx2++)
  94.             {
  95.                childWalker->addChild(new DataInTree(DataInTree(SKbooks[ndx2])));
  96.             }
  97.             break;
  98.  
  99.          case 2:
  100.             for (ndx2= 0; ndx2 < sizeof(SBbooks)/sizeof(char *); ndx2++)
  101.             {
  102.                childWalker->addChild(new DataInTree(DataInTree(SBbooks[ndx2])));
  103.             }
  104.             break;
  105.  
  106.          case 3:
  107.             for (ndx2= 0; ndx2 < sizeof(RDbooks)/sizeof(char *); ndx2++)
  108.             {
  109.                childWalker->addChild(new DataInTree(DataInTree(RDbooks[ndx2])));
  110.             }
  111.             break;
  112.  
  113.          default:
  114.             break;
  115.       }   // case end
  116.    }   // for end
  117.  
  118.    for (childWalker= (DataInTree *)Mommy.getChild();
  119.         childWalker != NULL;
  120.         childWalker= (DataInTree *)childWalker->getRight())
  121.    {
  122.       printf ("Author tah dahh\n");
  123.       childWalker->display();
  124.       printf ("   wrote the following masterpieces\n");
  125.       for (childWalker2= (DataInTree *)childWalker->getChild();
  126.            childWalker2 != NULL;
  127.            childWalker2= (DataInTree *)childWalker2->getRight())
  128.       {
  129.          childWalker2->display();
  130.       }
  131.    }
  132.  
  133.    printf("Test Tree Surgery Asimov Goes to another mommy\n");
  134.  
  135.    DataInTree   AsMom, *AsPtr= (DataInTree *)Mommy.getChild();
  136.    AsMom.addChild(AsPtr);
  137.  
  138.    printf("Test Tree Surgery Asimov Goes to another mommy ok\n");
  139.  
  140.    printf("Print the remaining family Tree\n");
  141.  
  142.    for (childWalker= (DataInTree *)Mommy.getChild();
  143.         NULL != childWalker;
  144.         childWalker= (DataInTree *)childWalker->getRight())
  145.    {
  146.       printf ("Author tah dahh\n");
  147.       childWalker->display();
  148.       printf ("   wrote the following masterpieces\n");
  149.       for (childWalker2= (DataInTree *)childWalker->getChild();
  150.            NULL != childWalker2;
  151.            childWalker2= (DataInTree *)childWalker2->getRight())
  152.       {
  153.          childWalker2->display();
  154.       }
  155.    }
  156.  
  157.    printf("Print Asimov family Tree\n");
  158.  
  159.    for (childWalker= (DataInTree *)AsMom.getChild();
  160.         NULL != childWalker;
  161.         childWalker= (DataInTree *)childWalker->getRight())
  162.    {
  163.       printf ("Author tah dahh\n");
  164.       childWalker->display();
  165.       printf ("   wrote the following masterpieces\n");
  166.       for (childWalker2= (DataInTree *)childWalker->getChild();
  167.            NULL != childWalker2;
  168.            childWalker2= (DataInTree *)childWalker2->getRight())
  169.       {
  170.          childWalker2->display();
  171.       }
  172.    }
  173.    printf("Test ended Successfully\n");
  174. }   // main end
  175.