/*
   Nodes.cc -- A node abstraction and a binary node abstraction

   Author: Larry Morell

   Algorithm:
      Nodes contain only information (strings in this case)
      BinNodes inherit from Nodes and contain left and right
      pointers for building binary trees or general trees. 

   Revision history:
   3/16/05 -- first implementation

*/
#include "Envs.h"
#include "Nodes.h"
Node::Node() {
   info = "";
}
Node::Node(string s) {
   info = s;
}
string Node::getInfo(){return info;}
void Node::setInfo(string s){info = s;}
/* ---------------  BinNode's ---------------- */
BinNode::BinNode () {
   left = NULL;
   right = NULL; 
}

BinNode::BinNode (string s, Node *l, Node *r) {
   setInfo(s);
   left = l;
   right = r;
}

void BinNode::setLeft (Node *n) { left=n;}
void BinNode::setRight (Node *n) { right=n;}
Node * &BinNode::getLeft () { return left;}
Node * &BinNode::getRight () { return right;}

int tindent=0;
void printTree (Node *n){
//   cout << "Entering printree with " << n << endl;
   for (int i=0; i<tindent; i++) cout << ' '; 
   if (n != NULL) 
   {
      cout << n->getInfo() << endl; //Output node info
      if (! n->isLeaf() ) {
         tindent = tindent+4; 
         BinNode *b = (BinNode *) n;
         printTree(b->getLeft());
         printTree(b->getRight());
         tindent = tindent-4; 
      }
   }
   else 
      cout << "NULL\n";
  // cout << "Leaving printree for " << n << endl;
}

