list.h
#ifndef LIST_H
#define LIST_H
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class node {
public:
string word;
node* next;
};
class list {
public:
list();
list(string file);
~list();
bool split(char alpha);
node* first();
size_t length();
string word;
string mask;
bool is_guessed();
private:
node* mFirst;
int lgth;
};
#endif /* LIST_H */
list.cpp
#include <iostream>
#include <fstream>
#include "list.h"
using namespace std;
list::list(string file) {
ifstream inputFile;
inputFile.open(file);
size_t count;
inputFile >> count;
mFirst = NULL;
for (int i = 0; i < count; i++) {
string word;
inputFile >> word;
// TODO: Create a node with this word, and add it to the beginning
// of the list
}
}
list::~list() {
// TODO: Implement the destructor
}
bool list::split(char guess) {
// TODO: Complete this method as directed by the comments
// 1) Create an array, called lists, of 64 pointers to list objects
// 2) In a loop instantiate 64 list objects and store pointers to
// them in the array
// 3) Traverse the linked list
// At each node:
// a) call update_mask with guess as an argument
// b) move the node so that it is in the array at lists[ndx] where
// ndx is the value returned by the call to get_mask(guess) on the node
// Note that this list will be empty at the end of this loop
// 4) Find the longest list in the array lists, stored the index of this in the
// variable best
// 5) Free the memory used by all lists except for lists[best]
// 6) Set the first node in this list to be equal to the first node in lists[best]
// and the length of this list to be the length of lists[best]
// 7) return true iff guess is in the string returned by mask()
}