This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { | |
| window = UIWindow(frame: UIScreen.mainScreen().bounds) | |
| let upAnimVC = UpAnimationViewController() | |
| window?.rootViewController = upAnimVC | |
| window?.makeKeyAndVisible() | |
| return true | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| vector<string> getWordsReachableInNSteps(element *start, int nSteps) { | |
| vector<string> reachableWords; | |
| queue<element *> Q; | |
| list<element *>::iterator linksIterator; | |
| start->distanceFromSource = 0; | |
| Q.push(start); | |
| while(! Q.empty()) { | |
| element *t_element = Q.front(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| string findLongestLadder(vector<element> &wordListDS) { | |
| int wordListSize = wordListDS.size(); | |
| int longestLadderSize= 0; | |
| string longestLadder; | |
| for (int i = 0; i < wordListSize; ++i) { | |
| if (wordListDS.at(i).noOfLadders > longestLadderSize) { | |
| longestLadderSize = wordListDS.at(i).noOfLadders; | |
| longestLadder = wordListDS.at(i).word; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| vector<string> getNextWordsForWord(element &entry) { | |
| vector<string> nextWords; | |
| list<element *>::iterator linksIterator; | |
| for (linksIterator = entry.links.begin(); | |
| linksIterator != entry.links.end(); ++linksIterator) | |
| { | |
| nextWords.push_back((*linksIterator)->word); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void updateNumberOfLadders(vector<element> &wordListDS) { | |
| int wordListSize = wordListDS.size(); | |
| for (int i = 0; i < wordListSize; ++i) | |
| { | |
| wordListDS.at(i).noOfLadders = wordListDS.at(i).links.size(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Maps a word to the index in the vector | |
| map<string, int> wordToVectorIndex; | |
| // Push the word to the vector | |
| while (cin >> word) | |
| { | |
| element e; | |
| e.word = word; | |
| e.noOfLadders = 0; | |
| e.isVisited = ELEMENT_NOT_VISITED; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct element | |
| { | |
| string word; | |
| int noOfLadders; | |
| list<element *> links; | |
| elementVisitHistory isVisited; | |
| int distanceFromSource; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| string findLongestLadder(vector<string> wordList) | |
| { | |
| int wordListSize = wordList.size(); | |
| unsigned int longestLadderSize = 0; | |
| string longestLadder; | |
| for (int i = 0; i < wordListSize; ++i) | |
| { | |
| vector<string> t_vector = getNextWordsForWord(wordList[i], wordList); | |
| if (longestLadderSize < t_vector.size()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| vector<string> getNextWordsForWord(string word, vector<string> wordList) | |
| { | |
| vector<string> nextWords; | |
| for (size_t i = 0; i < wordList.size(); ++i) | |
| { | |
| int diff = getDiffCount(word, wordList[i]); | |
| if (diff == 1) | |
| { |