Here's a parital fix. I fixed a couple of problems (noted in comments), and a couple of stylistic things in your first two functions. I didn't even look at the other functions, but it works better. It seems to still be missing one name.
int main()
{
ifstream fin ("a6.txt");
if (!fin) {
cout << "Input file does not exist.\n\n";
return -1;
}
AVLNode* head = AVLCreation (fin);
fin.close();
InorderTraversal (head);
cout << "\n\n";
PreorderTraversal (head);
cin.sync(); cin.get(); // Will work on more systems.
}
AVLNode *AVLCreation(ifstream &InFile)
{
AVLNode *Root = NULL;
AVLNode *Leaf, *temp, *Scan;
/*** Moved getline into the while condition since it is
a getline attempt that will inform you of the EOF.
You should add a check for blank names (or all spaces). */
string name;
while (getline (InFile, name))
{
temp = Root;
Leaf = new AVLNode;
Leaf->Name = name;
Leaf->Balance = 0;
Leaf->RightChild = NULL;
Leaf->LeftChild = NULL;
if (!Root)
{
Root = Leaf;
Scan = Root;
}
else
{
while (1)
{
if (Leaf->Name > temp->Name && !temp->RightChild)
{
temp->RightChild = Leaf;
temp->Balance--;
break;
}
else if (Leaf->Name < temp->Name && !temp->LeftChild)
{
temp->LeftChild = Leaf;
temp->Balance++;
break;
}
if (Leaf->Name > temp->Name && temp->RightChild)
{
/*** Switched the order of the next two lines */
temp = temp->RightChild;
temp->Balance--;
}
else if(Leaf->Name < temp->Name && temp->LeftChild)
{
/*** Ditto. */
temp = temp->LeftChild;
temp->Balance++;
}
}
PreorderScan(Root, Scan);
}
}
return Root;
}