// TreeDemo.cpp
// Tree data structure demonstration program.
// Created for use with USC's CS102 fall '99 lab 12.
// Copyright 1999 by Rick Wagner and USC. All rights reserved.
// Portions copyright by Main and Savitch (link2.h). Fair use
// for educational purposes.

#include <iostream.h>
#include "TreeNode.h"

// Global constants:
const char* gsVerNum = "1.00";

void main()
{
  int i = 0;
  int j = 0;
  int k = 0;
  int iBranchingFactor = 7;
  int iNumNodes = 0;
  TreeNode* root = NULL;
  TreeNode* foundChild = NULL;

  cout << "Tree demonstration program version " << gsVerNum << "." << endl << endl;

  // Build a small tree to test the search member function:
  root = new TreeNode(++iNumNodes);
  for (i = 0; i < iBranchingFactor; i++)
  {
    root->addChild(new TreeNode(++iNumNodes));
    for (j = 0; j < iBranchingFactor; j++)
    {
      root->getChild(i)->addChild(new TreeNode(++iNumNodes));
      for (k = 0; k < iBranchingFactor; k++)
      {
        root->getChild(i)->getChild(j)->addChild(new TreeNode(++iNumNodes));
      }
    }
  }

  // Test the findChild() method:
  foundChild = root->findChild(iBranchingFactor * iBranchingFactor * iBranchingFactor);
  if (foundChild != NULL)
  {
    cout << "Found child " << foundChild->getData() << endl;
  }
  else
  {
    cout << "Child not found in the tree." << endl;
  }
}
