i know how to get a file and all but how do u go about putting that file into the tree?
my get file
void BST::loadFile()
{
cout << "Enter the the file location" << endl;
cin >> inFileName;
inFile.open(inFileName.c_str());
if (!inFile.is_open()) //test for file
{
cerr << "Cannot open file: " << inFileName << endl;
getche();
}
while(!inFile.eof()) //loop through untill end of file
{
inFile >> lastName >> firstName;
cout << lastName << ", " << firstName << endl;
}// end obtain info
inFile.close();//close infile
}
do i just go key = inFile
here is my key struct
struct Key {
char* data; // string
Key();
Key(char* data) { this->data = new char[strlen(data)];
strcpy(this->data,data);}
~Key() {delete data;};
Key(Key& key);
void print();
Key& operator= (Key& key);
bool operator== (Key& key) { return 0 == strcmp(this->data,key.data);} // is this == to that key
bool operator< (Key& key) { return -1 == strcmp(this->data,key.data);}// is this < that key
bool operator> (Key& key) { return 1 == strcmp(this->data,key.data);} // is this > that key
};
Key::Key()
{
data = NULL;
}
Key::Key(Key& key)
{
data = key.data;
}
Key& Key::operator= (Key& key)
{
data = key.data;
return *this;
}
void Key::print()
{
cout << data << endl;
}
my BST Class
class BST_Node {
private:
Key key; // key holds the data
BST_Node* left; // ptr to left subtree
BST_Node* right; // ptr to right subtree
public:
// Managers
BST_Node();
BST_Node(Key key); // Construct given key-data
BST_Node(BST_Node& node); // Copy Constructor
~BST_Node(); // Destruct node
// Operators
BST_Node& operator= (BST_Node& node); // Assignment
// Accessors
Key getKey() {return key;}; // get Key Data
BST_Node* getLeft() {return left;}; // get root of left subtree
BST_Node* getRight() {return right;}; // get root of right subtree
void setLeft(BST_Node* node);
void setRight(BST_Node* node);
};
BST_Node::BST_Node()
{
key.data = NULL;
left = NULL;
right = NULL;
}
BST_Node::BST_Node(Key key)
{
cout << "enter key" << endl;
cin >> key.data;
}
BST_Node::BST_Node(BST_Node& node)
{
right = node.right;
left = node.left;
//key = node.key;
}
BST_Node::~BST_Node()
{
delete left;
delete right;
}
BST_Node& BST_Node::operator= (BST_Node& node)
{
right = node.right;
left = node.left;
//key = node.key;
return *this;
}
void BST_Node::setLeft(BST_Node* node)
{
this->left = node;
}
void BST_Node::setRight(BST_Node* node)
{
this->right = node;
}