Example #1
0
// Driver for testing the general tree implementation
int main() {
  GenTree<int> tree;
  GTNode<int>* ptr;
  GenTree<int> tree2;
  GTNode<int>* ptr2;

  tree.newroot(1, NULL, NULL);
  ptr = tree.root();
  cout << "Print the tree with one node\n";
  tree.print();
  ptr->insertFirst(new GTNode<int>(2));
  cout << "Print the tree with two nodes\n";
  tree.print();
  ptr = ptr->leftmostChild();
  cout << "ptr now at node " << ptr->value() << "\n";
  ptr->insertNext(new GTNode<int>(3));
  cout << "Print the tree with three nodes\n";
  tree.print();
  ptr->insertNext(new GTNode<int>(4));
  cout << "Print the tree with four nodes\n";
  tree.print();
  ptr = ptr->rightSibling();
  cout << "ptr now at node " << ptr->value() << "\n";
  ptr->insertFirst(new GTNode<int>(5));
  cout << "Print the tree with 5 nodes\n";
  tree.print();

  tree2.newroot(11, NULL, NULL);
  ptr2 = tree2.root();
  ptr2->insertFirst(new GTNode<int>(12));
  ptr2 = ptr2->leftmostChild();
  ptr2->insertNext(new GTNode<int>(13));

  return 0;
}