Hello all!!!
First off, I'd like to say THANK YOU for such a great site. I've learned a lot here in the last 2 months!
I'm currently in a Data Structures class and our current assignment is:
Read data from a .dat file (name, address, phone #) and store the info in a BST using the phone number as the unique key for each node.
I have been successful in opening the file, retrieving the information, and parsing it out. What I am not successful in is actually putting the info ON the tree.
Could somebody take a look and point me in the right direction? Thank you!
Jim
//Project: Populating a BST with a .DAT file and traversing the tree
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include "binarySearchTree.h"
using namespace std;
struct Data
{
string name;
string address;
};
template <class Data>
void insert (int key, Data data);
int main()
{
int key;
const int MAXCHARS = 81;
Data data;
BST <int, Data> tree;
ifstream dfile;
dfile.open ("phone.dat");
while (dfile.good())
{
string phone, name, address;
std::getline(dfile, phone, ':');
std::getline(dfile, name, ':');
std::getline(dfile, address, '\n');
key = atoi(phone.c_str());
// cout << "The phone # is: " << phone << endl;
// cout << "The name is: " << name << endl;
// cout << "The address is: " << address << endl;
tree.insert (key, data);
cout << "The phone # for " << address << "is: " << phone << endl;
cout << "\nThe unique key is: " << key << endl;
}
dfile.close();
return 0;
}
I hope I used the code tags correctly!
Thank you again,
Jim
P.S. - I did not include the binarySearchTree.h file, but if you need to know part of it I can include it.