Hello can someone help me with this c program called word la

Hello, can someone help me with this c++ program, called word laders. i have some header files so far.

Word Ladders The game of word ladders was invented by Lewis Carroll in 1878 during Christmas vacation when he apparently had too much time on his hands. The game is really quite simple: the player must find a way to transform one English word into another by successively changing only a single letter. At each stage, the intermediate values must also be English words. For example, the word jump may be transformed into the word play through the transformations jumppump pomp > poop > plop ploy -play We don\'t have enough free time these days to do this by hand, but we can automate the procedure. You will create a graph of a large number of words with edges between words that differ by only a single letter. In fact, since it should be clear that each word in the above list transformation has the same number of letters, you will be creating a number disjoint graphs, one for words with three letters, one for words with four letters and so forth Armed with this graph, you will perform a breadth-first search of the graph starting from a given starting word. As usual, as you perform the search, you will mark the parent of each visited node. Also, you will accumulate each word visited in a list. Now you can find the desired ending word in this list and walk backwards to the given starting word. This will be the shortest path from the starting word to the ending word A suitable list of words is the dictionary built in to any Linux system, I have placed one on the ‘N\' drive on our folder. It is called simply american_english. You should use this for your project; it contains roughly 100,000 words. The words are both upper and lower case, and some also contain apostrophes. You should transform all the words to upper or lower case -- it doesn\'t matter which and discard those that contain apostrophes When building your graph you should use the adjacency list representation. You will find it convenient to accumulate a map from each word entered into the graph to its index in the adjacency list. You may find it convenient to use the following structures when building your graph:

Solution

program

   class Sol
{
public:
bool Step1(string src, string des)
{
if(src.length() != des.length()) return false;
int difference = 0;
for(int i=0; i<src.length(); i++)
{
if(src[i]!=des[i])
{
difference++;
if(difference>1) return false;
}
}
if (difference==0) return false;
else return true;
}
int ladderLength(string start, string end, unordered_set<string> &dict)
{
vector<string> inter;
inter.push_back(start);
dict.erase(start);
int size = inter.size();
int result = 1;
int i;
unordered_set<string>::iterator it;
while(!inter.empty())
{
for(i=0; i<size; i++)
{
if(Step1(inter[i], end))
{
result++;
return result;
}
it = dict.begin();
while(it!=dict.end())
{
if(Step1(inter[i],*it))
{
inter.push_back(*it);
it = dict.erase(it);
}
else
{
it++;
}
}   
}
result++;
inter.erase(inter.begin(), inter.begin()+size);
size = inter.size();
}
return 0;
}
};

Hello, can someone help me with this c++ program, called word laders. i have some header files so far. Word Ladders The game of word ladders was invented by Lew
Hello, can someone help me with this c++ program, called word laders. i have some header files so far. Word Ladders The game of word ladders was invented by Lew

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site