home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
SAMPLES
/
COMPILER
/
SAMPLE06
/
AUTHORS2.CPP
< prev
next >
Wrap
Text File
|
1993-04-03
|
7KB
|
175 lines
//+----------------------------------------------------------------------------+
//| PROGRAM NAME: TSTTREE.CPP |
//| ------------ |
//| |
//| COPYRIGHT: |
//| ---------- |
//| Copyright (C) International Business Machines Corp., 1992,1993. |
//| |
//| 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. |
//| |
//| REVISION LEVEL: 1.0 |
//| --------------- |
//| |
//+----------------------------------------------------------------------------+
//| Purpose : Another tree tester |
//| Author : njC Sales |
//| Date : 27 October 1992 |
//+----------------------------------------------------------------------------+
#include <stdio.h>
#include "gentree.hpp"
#include "treedata.hpp"
void main()
{
char *authors[] = {"Asimov, Isaac",
"Sales, Kevin Matthew",
"Stroustrup, Bjarne",
"Richie, Dennis"
};
char *AIbooks[] = {"Foundation",
"I Robot",
"Caves of Steel"
};
char *SKbooks[] = {"Compiler Design",
"Man Machine Communication",
"I came, I C"
};
char *SBbooks[] = {"C++ Programming Language",
"The ARM",
};
char *RDbooks[] = {"C Programming Language",
"Yet another C",
};
GenTree<TreeData> Mommy;
GenTree<TreeData> *childWalker, *childWalker2;
int index, ndx2;
for (index= 0; index < sizeof(authors)/sizeof(char *); index++)
{
Mommy.addChild(new GenTree<TreeData>(TreeData(authors[index])));
}
printf("The Authors are.. tah dahhhhh\n");
for (childWalker= (GenTree<TreeData> *)Mommy.getChild();
childWalker != NULL;
childWalker= (GenTree<TreeData> *)childWalker->getRight())
{
childWalker->display();
}
printf("Now Adding books to authors\n");
for (index= 0, childWalker= (GenTree<TreeData> *)Mommy.getChild();
childWalker != NULL;
index++, childWalker= (GenTree<TreeData> *)childWalker->getRight())
{
childWalker->display();
switch(index)
{
case 0:
for (ndx2= 0; ndx2 < sizeof(AIbooks)/sizeof(char *); ndx2++)
{
childWalker->addChild(new GenTree<TreeData>(TreeData(AIbooks[ndx2])));
}
break;
case 1:
for (ndx2= 0; ndx2 < sizeof(SKbooks)/sizeof(char *); ndx2++)
{
childWalker->addChild(new GenTree<TreeData>(TreeData(SKbooks[ndx2])));
}
break;
case 2:
for (ndx2= 0; ndx2 < sizeof(SBbooks)/sizeof(char *); ndx2++)
{
childWalker->addChild(new GenTree<TreeData>(TreeData(SBbooks[ndx2])));
}
break;
case 3:
for (ndx2= 0; ndx2 < sizeof(RDbooks)/sizeof(char *); ndx2++)
{
childWalker->addChild(new GenTree<TreeData>(TreeData(RDbooks[ndx2])));
}
break;
default:
break;
} // case end
} // for end
for (childWalker= (GenTree<TreeData> *)Mommy.getChild();
childWalker != NULL;
childWalker= (GenTree<TreeData> *)childWalker->getRight())
{
printf ("Author tah dahh\n");
childWalker->display();
printf (" wrote the following masterpieces\n");
for (childWalker2= (GenTree<TreeData> *)childWalker->getChild();
childWalker2 != NULL;
childWalker2= (GenTree<TreeData> *)childWalker2->getRight())
{
childWalker2->display();
}
}
printf("Test Tree Surgery Asimov Goes to another mommy\n");
GenTree<TreeData> AsMom, *AsPtr= (GenTree<TreeData> *)Mommy.getChild();
AsMom.addChild(AsPtr);
printf("Test Tree Surgery Asimov Goes to another mommy ok\n");
printf("Print the remaining family Tree\n");
for (childWalker= (GenTree<TreeData> *)Mommy.getChild();
NULL != childWalker;
childWalker= (GenTree<TreeData> *)childWalker->getRight())
{
printf ("Author tah dahh\n");
childWalker->display();
printf (" wrote the following masterpieces\n");
for (childWalker2= (GenTree<TreeData> *)childWalker->getChild();
NULL != childWalker2;
childWalker2= (GenTree<TreeData> *)childWalker2->getRight())
{
childWalker2->display();
}
}
printf("Print Asimov family Tree\n");
for (childWalker= (GenTree<TreeData> *)AsMom.getChild();
NULL != childWalker;
childWalker= (GenTree<TreeData> *)childWalker->getRight())
{
printf ("Author tah dahh\n");
childWalker->display();
printf (" wrote the following masterpieces\n");
for (childWalker2= (GenTree<TreeData> *)childWalker->getChild();
NULL != childWalker2;
childWalker2= (GenTree<TreeData> *)childWalker2->getRight())
{
childWalker2->display();
}
}
printf("Test ended Successfully\n");
} // main end