Advertisement
Guest User

TestC.cc

a guest
Dec 2nd, 2018
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <limits.h>
  4. #include <time.h>
  5.  
  6. class TestC {
  7. public:
  8.     TestC*child1;
  9.     TestC*child2;
  10.     TestC*child3;
  11.  
  12.     TestC(int depth) {
  13.         if (depth>0) {
  14.             depth-=1;
  15.             child1=new TestC(depth);
  16.             child2=new TestC(depth);
  17.             child3=new TestC(depth);
  18.         } else {
  19.             child1=NULL;
  20.             child2=NULL;
  21.             child3=NULL;
  22.         }
  23.     }
  24.     ~TestC() {
  25.         if (child1!=NULL) delete child1;
  26.         if (child2!=NULL) delete child2;
  27.         if (child3!=NULL) delete child3;
  28.  
  29.     }
  30.  
  31.     int Count() {
  32.         int count=1;
  33.         if (child1!=NULL) count+=child1->Count();
  34.         if (child2!=NULL) count+=child2->Count();
  35.         if (child3!=NULL) count+=child3->Count();
  36.         return count;
  37.     }
  38. };
  39.  
  40. int main(int argc, char*argv[]) {
  41.     if (argc<3) {
  42.         printf("TestC <depth> <reps>\n");
  43.         return 0;
  44.     }
  45.     int depth=atoi(argv[1]);
  46.     int reps=atoi(argv[2]);
  47.     printf("TestC started depth=%d reps=%d\n",depth,reps);
  48.     int count = 0;
  49.     for(int rep=0; rep<reps; rep++) {
  50.  
  51.         TestC*t=new TestC(depth);
  52.         count=t->Count();
  53.         delete t;
  54.  
  55.  
  56.     }
  57.     printf("TestC count=%d\n", count);
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement