I'm working on a BST for the first time and need some big time help. I've gotten some of the functionality written and was wanting to test it so I've got this simple code that Inserts a node into the tree and then reads it:
When I debug its getting an error in the TestPrint function, which is here:Code:#include <string>
using namespace std;
void main()
{
CharString name = "Tyson";
CharString att1 = "Is a scud";
CharString att2 = "Is Married";
int attcnt = 2;
TreePtr X = new Node;
strcpy(X->Info.Name, name);
X->Info.AttributeCount = attcnt;
strcpy(X->Info.Attribute[0], att1);
strcpy(X->Info.Attribute[1], att2);
BST Original;
Original.Insert (X);
Original.TestPrint (X);
cout << "Do you want to continue?"<<endl;
int spare;
cin >> spare;
}
It goes through the loop fine the first time but when it hits TestPrint (P->Left) the second time it dies. I get this message:Code:void BST::TestPrint (TreePtr P)
{
if (P)
{
TestPrint (P->Left);
cout << Root->Info.Name << endl;
TestPrint (P->Right);
}
}
Unhandled exception at 0x00433f4c in Binary_Search_Tree.exe: 0xC0000005: Access violation reading location 0xcdcdcee9.
Can someone help find the problem. I would appreciate it.