hey,
im trying to create a word ladder but am getting stuck. Im able to get the words which differ by one character apart but now i dont know where to go from here..can someone please give me a hint or idea as to where i should go from here.. here is what i got so far..
just in case you dont know a word ladder is ladder which connects from one word to another..example a ladder from code to data is
code -> core -> care -> dare -> date -> data
Code:
#include "lexicon.h"
#include "queue.h"
#include "vector.h"
#include <iostream>
bool printOneAway(string,string,int,Lexicon);
int main() {
string sWord,eWord;
Lexicon english("EnglishWords.dat");
while(true)
{
cout << "Enter Start Word:";
cin >> sWord;
cout << "Enter End Word:";
cin >> eWord;
for(int i = 0 ; i < sWord.size(); i++)
{
if(printOneAway(sWord,eWord,i,english))
break;
cout << endl;
}
}
return 0;
}
bool printOneAway(string first,string last, int position, Lexicon lex)
{
Vector<string> ladder;
string temp = first;
ladder.add(first);
for(char c = 'a' ; c != 'z'; c++)
{
temp[position] = c;
if(lex.containsWord(temp) && temp != first)
{
ladder.add(temp);
if(temp == last)
{
for(int i = 0 ; i < ladder.size(); i++)
cout << ladder[i] << endl;
return true;
}
}
}
return false;
}