// Codebook.h // Stores each plaintext and code associated with the // plaintext in a Doubly linked list, // ordered on plaintext phrases; // dll is constructed from a text file // which is in random order // dll consists of Nodes #ifndef CODEBOOK_CLASS #define CODEBOOK_CLASS #include "Node.h" #include class Codebook { private: Node * wordlist; public: // default constructor Codebook(); // constructor based upon text in Pair Codebook(Pair); // constructor with Pair and pointers left and right Codebook(Pair, Node *, Node *); // copy constructor Codebook(const Codebook &); // destructor ~Codebook(); // assignment operator Codebook & operator=(const Codebook &); // reads the text file // the argument is the name of the text file // creates a Pair for each text and code // creates a Node pointer to the pair // throws an exception if the file is empty or does not exist void reader(const char *); // makes a Pair out of a single line of input Pair makePair(std::string); // inserts the node into the correct place in the dll // dll is ordered on strings, alphbetically (low to high) void insert(Node *); // deletes the Node containing the string from dll Codebook // returns true if the Node was deleted bool erase(std::string); // does the work to empty the dll // THIS FUNCTION IS RECURSIVE void makeEmpty(Node *); // does the copying of the entire dll // this is a deep copy void clone(const Codebook &); // locates the nodes in dll BETWEEN which // a node containing the string should be inserted // prev < node-to-be-inserted < curr // returns true if we are not at the end of the dll bool locate(std::string,Node *& prev,Node *& curr); // finds the node containing a specific plaintext string // returns true if the string is found // otherwise it returns false bool locate(std::string); // finds the node containing a specific plaintext string // returns true if string is found // otherwise it returns false bool locate(std::string, Node *&); // prints the dll from front to rear // prints one node per line: // plaintext followed by a single space followed by code void print() const; private: // you may put any private methods here // initializes all private data members void init(); }; #endif // CODEBOOK_CLASS