// remember, to compile you need to have list.C, list.h, and labex1.C // all in the same directory // the outline below is for list.C, // I have provided list.h and labex1.C on the lab page // // the compile command is // g++ -Wall labex1.C list.C -o labex1 // // to run the program without an input file use // ./labex1 // to run the program and have it read from an input file use // ./labex1 yourfilename // =============== list.C outline ========================== #include #include "list.h" using namespace std; // insertEntry // ----------- // adds one key/value pair to the front of the list // as long as the key does not already appear in the list // returns true if successful, false otherwise bool insertEntry(string key, string value, keyValue* &list) { // try lookup on key, list // and if it returns anything except null then return false // allocate a new keyvalue, store the pointer in a vaiable // and if it returns null then return false // set all four fields in the new item // (including copying list to the next field) // if list is null just make it point at the new item // otherwise make list's prev field point at the new item // return true } // lookupEntry (internal use) // ----------- // search the list or an entry matching the specified key, // return a pointer to the entry if found, // return null otherwise keyValue* lookupEntry(string key, keyValue* list) { // set up a pointer variable and make it a copy of list // while that variable isn't null, // if its key matches what you're looking for then return the pointer // otherwise make the variable point to the next item // if you get out of the while loop just return null } // lookupEntry (public use) // ----------- // search the list or an entry matching the specified key, // set the matching value and return true if found, // return false otherwise bool lookupEntry(string key, string &value, keyValue* list) { // call lookupEntry to find the right keyValue item // if it is null return false // otherwise set value equal to the item's value // and return true } // changeEntry // ----------- // search the list or an entry matching the specified key, // set the new value and return true if found, // return false if an entry for the key is not found bool changeEntry(string key, string &value, keyValue* list) { // call lookupEntry to find the right keyValue item // if it is null return false // otherwise set the item's value equal to the parameter value // and return true } // deleteEntry // ----------- // search the list or an entry matching the specified key, // remove the entry from the list, delete it, // and return true if found, // return false otherwise bool deleteEntry(string key, keyValue* &list) { // call lookupEntry to find the right keyValue item // if it is null return false // otherwise // if the item's prev field is null // then set list to the item's next field // (since we're getting rid of the old front item) // otherwise // get the previous item and set it's next field // to be the same as the current item's next // if the item's next field isn't null // get the next item and set it's prev field // to be the same as the current item's prev // return true } // displayEntries // -------------- // display each key/value pair in the list, // with one key/value pair per line of output void displayEntries(keyValue* list) { // declare a pointer var and copy the list parameter to it // while it isn't null // print that item's key and value, and // set the item to point to the next item } // insertFromFile // -------------- // if the specified file cannot be opened return -1, // otherwise // add each key/value pair in the file to the list // returning a count of the total number of successful inserts // assumes the file contains an even number of lines, // alternating between keys and numbers, e.g. // Fred Jones // 555-123-4567 // Scoobert Doo // 555-987-6543 // etc. int insertFromFile(char filename[], keyValue* &list) { // create a variable to count the successful inserts, // initializing it to zero // declare an ifstream variable // open the file // if the open failed return -1 // otherwise // while not at the end of the file // read one line of text into a char array (for the key) // if not at the end of the file // read one line of text into another char array (for the value) // if not at the end of the file // call insert on the key/value, and // if it returned true increment the number of inserts // close the file // return the number of inserts }