pinsickle 17 Junior Poster in Training

Ok guys, i'll say this first. I got it 99% working (100 % working if I test it with the much shorter name list that we are suppose to use for the homework.) For some reason the code skips the very last name. Honestly, I think I am over thinking the problem and making my code overly complex. Any help would be appreciated. Posted below is my code and the File I am reading from.

void BinarySearchTree::writeIteratively (ostream& outfile) const {
   TemplateStack <Node*> writeStack;
   Node* current = root; 
      
      while (current -> getLeft () != 0){ // loop to find first (farthest left) name
         writeStack.push(current);
         current = current -> getLeft ();
      }
      outfile << *current << endl; // displaying farthest left name
      do {
         
         while (current -> getRight () != 0){ // since 'smallest' name has been found starting to traverse right
            current = current -> getRight ();
            while (current -> getLeft () != 0){ // smaller name is tree found so traverse left
               writeStack.push (current);
               current = current -> getLeft();
            }
            outfile << *current << endl;
         }
         writeStack.pop (current);
         outfile << *current << endl;
         
         if (*current == *root){ // back at the top of the tree
            while (current -> getRight () != 0){ // repeat process from above to traverse right side of tree
            current = current -> getRight ();
            while (current -> getLeft () != 0){
               writeStack.push (current);
               current = current -> getLeft();
            }
            outfile << *current << endl;
         }
            writeStack.pop (current);
            outfile << *current << endl;
         }
      }while (!writeStack.isEmpty ()); 
}

Here is the file i am reading from

Smith 555-1234
Jones 555-4321
Tully 555-2314
Baker 555-4123
Green 555-3412
Camp 555-1234
Kent 555-4321
Young 555-2314
Roberts 555-4123
Williams 555-3412
Dell 555-1234
Oliver 555-4321
Vans 555-4123
Evans 555-3412
Johnson 555-1234
Madison 555-4321
Parker 555-2314
Henderson 555-4123
Lamb 555-3412
Frank 555-1234
Noob 555-4321
Zoolander 555-2314
Adams 555-4123
Ingram 555-3412

This is the file I read from to create the tree. As stated earlier my code prints out this list of names in order, but completely omits the 'greatest' name Zoolander.
Thanks for any help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.