Thread: pointer help
View Single Post
Old Apr 4th, 2006, 11:18 PM   #61
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
      cout << node->left->getValue();
      cout << node->getValue();
      cout << node->right->getValue();
      
        printNode(node->getLeft(), level + 1);
        printNode(node->getRight(), level + 1);
Those cout's are trying to access the value out of left and right without checking whether it is null.
You don't want to print just the left and right value before and after this node's value, you want to print the left and right tree. You just have to move your recursive calls around a bit.
Try:
      printNode(node->getLeft(), level + 1);
      for(int i = 0; i < level; i++)
        cout << "\t";
      cout << node->getValue();
      cout << "\n";
      printNode(node->getRight(), level + 1);
The Dark is offline   Reply With Quote