From: Brad_Appleton@ivhs.mot.com Chapter 17.3: Assignment 1 Karl Lieberherr writes: > cout << "\nSecond Tree" << "\n"; > Tree *t2 = new Tree(n1, t1, t1); > cout<<"\ndepth of tree 2 ="; > cout<depth(); > cout<<"\nsize of tree 3 ="; Shouldnt the above read "size of tree 2 ="??? > cout<size(); > > cout << "\nThird Tree" << "\n"; > Tree *t3 = new Tree(n1, t2, t1); > cout<<"\ndepth of tree 3 ="; > cout<depth(); > cout<<"\nsize of tree 5 ="; Shouldnt the above read "size of tree 3 ="??? > cout<size(); > } > // output to be produced > //First Tree > // > //depth of tree 1 =1 > //size of tree 1 =1 > //Second Tree > // > //depth of tree 2 =2 > //size of tree 3 =3 > //Third Tree > // > //depth of tree 3 =3 > //size of tree 5 =5 I get the following output: First Tree depth of tree 1 =1 size of tree 1 =1 Second Tree depth of tree 2 =2 size of tree 2 =3 Third Tree depth of tree 3 =3 size of tree 3 =5 The difference between my output and yours is: < size of tree 3 =3 --- > size of tree 2 =3 ***** < size of tree 5 =5 --- > size of tree 3 =5 I would be so bold as to suggest that my output is correct (based on the coding errors I mentioned previously). I used a common routine to print the trees (I hate redundant code). The print routine plus my main() are as follows: void print_tree_stats(const char * aName, int aNumber, Tree * aTree) { cout << aName << " Tree\n" << "depth of tree " << aNumber << " =" << aTree->depth() << "\n" << "size of tree " << aNumber << " =" << aTree->size() << "\n"; } main () { DemNumber *n1 = new DemNumber(); Tree *t1 = new Tree(n1, 0, 0); print_tree_stats("First", 1, t1); Tree *t2 = new Tree(n1, t1, t1); print_tree_stats("Second", 2, t2); Tree *t3 = new Tree(n1, t2, t1); print_tree_stats("Third", 3, t3); } ____________________"And miles to go before I sleep."_____________________ Brad Appleton, Software Engineer Motorola Automotive Energy & Controls E-mail: appleton@ivhs.mot.com Positioning and Navigation Systems Phone: 708-714-7104 4000 Commercial Avenue, Mailstop 23 Fax: 708-714-7200 Northbrook, IL USA 60062-1840 response: Your print routine is the right way to do it. I took notes for the next edition. Regarding the output, I wanted it easy to check. So it should be: 1=1 2=2 3=3 I should have written: "depth of tree should be 1 and actual depth is" << t1 -> depth(); etc. -- Karl L.