/* * wordlist.cpp * * Created on: Oct 19, 2010 * Author: fischer * for use in Yale course CPSC 427a, Fall 2010 */ #include "wordlist.hpp" // -------------------------------------------------------- // Construct empty list with dummy header WordList::WordList() : dummy(""), tail(&dummy) { } WordList::~WordList() { WordEntry* scan = dummy.next; WordEntry* nextScan; while (scan != NULL) { nextScan = scan->next; delete scan; scan = nextScan; }; } // Scan word list for first subword of word WordEntry* WordList::findParent(const Word& word) const { WordList::iterator p; for (p = begin(); p != end(); p++) { if (*p <= word) { return p; // return first match } } return NULL; // not found } // Create WordEntry from Word and append it to WordList WordEntry* WordList::add(const Word& word) { WordEntry* temp = new WordEntry(word); tail->next = temp; tail = temp; return temp; } // Print the word list ostream& WordList::print(ostream& out) const { iterator p; for (p = begin(); p != end(); p++) { out << *p << endl; } return out; }