Alright, I need to create an N-ary tree that contains a list of words all of the same length so that we can create a word ladder from it. Given a word (like cat), we are suppose to put that as the root and from a dictionary we are given, supposed to fill in the tree so that nodes point to nodes that are one letter off. So, cat should point to the words like bat, eat, hat, cot, can, cap, etc. The part that seems to be throwing me is that bat needs to also point to the words like eat and hat as well as point to it's select words like bet and bag.
I was working on writing an insert function, but I'm stuck because of that fact. I did arrange the words so that those that were 1 letter off would come first, that way getting listed under the root before attempting to scale the rest of the tree. But I some how need to then compare all the children to the other nodes in the tree, and if off by one, add pointers between them as well.
Would I be better doing that after all the words are in the tree, or should I do that while I insert a new node, or is there a better way to handle this?
And, when making the new node, how should I handle the vector? Should I just let it stay empty until we know that it's the parent of something new, or should I put something in it for the time being? This is what I have so far before actually realizing that I'm not sure what I'm doing.
struct node
{
node* parent;
vector <node*> children;
string data;
};
void NTree::insert(string d)
{
node* t = new node;
node* parent = NULL;
vector <node*> children;
t->data = d;
if(isEmpty()) root = t; // if new tree, make insert the root
else
{ node* curr;
curr = root;
....
}
}