binary tree problem
i'm building a binary tree the problem is when i'm reading from e text file .First i'm sending to tree builder function a empty node and e new node the function return me firt node of a tree, but when i try to built the secund node ,i dont anderstend whay, my program write to my new node and to first tree node;
string readLine(istream& fin)
{
char buff[256];
// Clear any remaining end of line characters
if(fin.peek()=='\n')
{
fin.ignore();
}
fin.getline(buff, 256, '\n');
return string(buff);
}
Node* readFile(Node* tree)
{
string value[5];
Node* load=new Node();
int temp=0,i;
ifstream inFile("c://treeFile.txt");
// Open files
if (!inFile)
{
// Error
cout << "input file not found" << endl;
}
else
{
// Read input file until end reached
while (!inFile.eof())
{
// Read data from file
value[temp]=readLine(inFile);
if(temp==4)
{
//Create node
load->name=value[0];
load->surname=value[1];
load->adress=value[2];
load->phoneNo=value[3];
load->Email=value[4];
load->value=charValor(value[0]);
load->pLeft =0;
load->pRight =0;
//Build tree
tree=addNode(tree,load);
temp=0;
for(i=0;i<5;i++)
{
value[i]="null";
}
}
else
{
temp++;
}
}
inFile.close();
return tree;
}
}
this are the function that build the nodes and read from file;
|