Skip to content

Instantly share code, notes, and snippets.

@rajkumar-p
Created January 17, 2013 13:12
Show Gist options
  • Save rajkumar-p/4555854 to your computer and use it in GitHub Desktop.
Save rajkumar-p/4555854 to your computer and use it in GitHub Desktop.
Build ladder data structure
void buildLadderDataStructure(vector<element> &wordListDS)
{
int wordListSize = wordListDS.size();
for (int i = 0; i < wordListSize; ++i)
{
for (int j = i + 1; j < wordListSize; ++j)
{
element e1 = wordListDS.at(i);
element e2 = wordListDS.at(j);
int diff = getDiffCount(e1.word, e2.word);
if (diff == 1) {
wordListDS.at(i).links.push_back(&wordListDS.at(j));
wordListDS.at(j).links.push_back(&wordListDS.at(i));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment