// CSE143 Sp01 Homework 1 Sample Solution // WordList.cpp - implementation of WordList data structure and functions // SRB 6/20 #include using namespace std; #include "wordlist.h" // Make words an empty WordList void makeWordListEmpty(WordList &words) { words.size = 0; } // Add a word pair to the word list. // Assumption: list is not full void addWord(WordList &words, string badWord, string goodWord) { words.list[words.size].wrongWord = badWord; words.list[words.size].rightWord = goodWord; words.size++; } // Look for word in WordList words. If found, store coordinates in corrected Word in // correctWord and set found = 0; if not found set found = 1 and copy token to correctWord. void queryWordList(WordList &words, char *token, string &correctWord, int &found) { int k = 0; //used to get the index of the element in the word list which matches out query string queryWord = token; //copies the token into a string so that it can be compared while (k < words.size && words.list[k].wrongWord != queryWord) { k++; } if (k < words.size) { //if we've found a match.. found = 1; correctWord = words.list[k].rightWord; } else { correctWord = queryWord; found = 0; } }