#include "laddernode.h"


LadderNode::LadderNode (const string & newWord)
  : myWord(newWord),
    myVisited(false),
    myAncestor(NULL)
{}


bool LadderNode::IsEqual (const LadderNode & rhs) const
// post: returns true if words within nodes are equal
{
    return myWord == rhs.myWord;
}


bool LadderNode::IsOneApart (const LadderNode & rhs) const
// post: returns true if and only if differ from rhs by exactly
//       one letter
{
    int diff = 0;

    int k;
    for (k = 0; k < myWord.length(); k++)
    {
        if (myWord[k] != rhs.myWord[k])
        {
           diff++;
           if (diff > 1) return false;
        }
    }

    return (diff == 1);
}


bool LadderNode::IsVisited () const
{
    return myVisited;
}


void LadderNode::Print (ostream & output) const
{
    output << myWord;
}


void LadderNode::Visit ()
{
    myVisited = true;
}


void LadderNode::DeriveFrom (LadderNode * ancestor)
{
    myAncestor = ancestor;
}


void LadderNode::Clear ()
{
    myVisited = false;
    myAncestor = NULL;
}
